Algorithm ๐ง๐ป๐ป/Leetcode31 [Leetcode,c++] Add Digits ๋ฌธ์ https://leetcode.com/problems/add-digits/ Add Digits - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์ฝ๋ (1) ์ฌ๊ท, ๋ฐ๋ณต๋ฌธ์ ์ฌ์ฉํ ํ์ด class Solution { public: int addDigits(int num) { int temp1=0, temp2=0, ans=num; while(true){ while(num>9){ temp1 = num%10; temp2 = num/10; ans = temp1 +.. 2022. 3. 2. [Leetcode,c++] Happy Number ๋ฌธ์ Happy Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์ฝ๋ class Solution { public: bool isHappy(int n) { string s; s = to_string(n); while(true){ unsigned long long temp = 0; for(int i=0; i 2022. 3. 2. [Leetcode,c++] Majority Element ๋ฌธ์ Majority Element - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์ฝ๋ class Solution { public: int majorityElement(vector& nums) { mapm; for(int i:nums) m[i]++; int cnt=-1,ans; for(auto it=m.begin(); it!=m.end(); it++){ if(it->second>cnt){ cnt=it->second; ans=it->first; }; } ret.. 2021. 11. 28. [Leetcode,c++] Network Delay Time ๋ฌธ์ Network Delay Time - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์ฝ๋ class Solution { public: vectorgraph[101]; int d[101]; void dijkstra(int start){ priority_queuepq; pq.push({0,start}); d[start]=0; while(!pq.empty()){ int dist = -pq.top().first; int now = pq.top().second; p.. 2021. 11. 22. [Leetcode,c++] Valid Anagram ๋ฌธ์ Valid Anagram - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์ฝ๋ class Solution { public: bool isAnagram(string s, string t) { sort(s.begin(),s.end()); sort(t.begin(),t.end()); if(t==s) return true; else return false; } }; ํ์ด Anagram ์ด๋ ํ ๋ฌธ์์ด์ ๋ฌธ์๋ฅผ ๋น ์ง์์ด ์ฌ์ฉํ์ฌ ๋ค๋ฅธ ๋ฌธ์์ด์ ๋ง๋ค ์ ์๋ ๊ฒฝ์ฐ๋ฅผ.. 2021. 11. 20. [Leetcode,c++] Single Number ๋ฌธ์ Single Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์ฝ๋ class Solution { public: int singleNumber(vector& nums) { mapm; int ans; for(int i:nums) m[i]++; for(auto it = m.begin(); it!=m.end(); it++){ if(it->second==1){ ans=it->first; break; } } return ans; } }; ํ์ด ๋จ์ํ ๋ฐฐ.. 2021. 11. 19. [Leetcode,c++] Combination Sum II ๋ฌธ์ Combination Sum II - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์ฝ๋ class Solution { public: void dfs(int index, vector& candidates, int target, vector& ans, vector¤t){ if(target==0){ ans.push_back(current); return; } for(int i=index; iindex && candidates[i]==candidate.. 2021. 11. 16. [Leetcode,c++] Subsets II ๋ฌธ์ Subsets II - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์ฝ๋ class Solution { public: mapvisited; vectorans; void dfs(int num, vector&nums,vectorcurrent){ sort(current.begin(),current.end()); if(!visited[current]){ ans.push_back(current); visited[current]=1; } if(num>nums.siz.. 2021. 11. 15. [Leetcode,c++] Rotate Image ๋ฌธ์ Rotate Image - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์ฝ๋ ์๋ก์ด ๊ณต๊ฐ ์ ์ธ class Solution { public: void rotate(vector& matrix) { int n = matrix.size(); vectorans(n); for(int i=0; i=0; k--){ ans[i].push_back(matrix[k][i]); } } matrix = ans; } }; ์ ์๋ฆฌ ํ์ class Solution { public: .. 2021. 11. 15. ์ด์ 1 2 3 4 ๋ค์