๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

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.