본문 바로가기
반응형

Algorithms119

[알고리즘] Intersection of Two Arrays 2 포인트 1. map, dictionary 를 이용해서 수를 계산을 하고 중복되는 값을 찾아보자 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp #include using namespace std; class Solution { public: vector intersect(vector& nums1, vector& nums2) { unordered_map map; if(nums1.size() 0){ map[ele]-=1; result.push_back(ele);.. 2021. 2. 13.
[알고리즘] Excel Sheet Column Number 포인트 1. map, 딕셔너리를 사용하면 간단하게 풀 수 있습니다. 또한, 파이썬에서는 ord(), chr() C++ 에서도 변형하여 사용할 수 있으니 참고하시면 좋습니다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp #include using namespace std; class Solution { public: int titleToNumber(string s) { string standard = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; unordered_map map; for (int i=0; i0){ if(s.size()==1){ result+=(map[s[0]]*a); s=""; } else{ result += (map[s[s.size()-1]]*a); s .. 2021. 2. 12.
[알고리즘] Number of Steps to Reduce a Number to Zero 포인트 1. 홀수, 짝수 개념은 생각보다 많이 사용하니 잘 사용하면 굿!!! 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp class Solution { public: int numberOfSteps (int num) { int i=0; while (num>0){ i+=1; if(num&1){ num-=1; continue; } else{ num/=2; continue; } } return i; } }; python class Solution: def numIdenticalPairs(self, nums: List[int]) -> int: a = 0 for i in range(len(nums)): for j in range(i+1, len(nums)): if(nums[i]==num.. 2021. 2. 12.
[알고리즘] Determine if String Halves Are Alike 포인트 1. 모음을 찾아서 개수를 세어주는 문제이다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp #include using namespace std; class Solution { public: string basic = "aeiouAEIOU"; int cnt(string s){ int count = 0; for(auto ele : s){ if(basic.find(ele)!=string::npos) count+=1; } return count; } bool halvesAreAlike(string s) { string a, b; for (int i = 0; i < s.size(); i++) { if(i bool: a, b = self.cnt(str(s[:len(s)//2])),.. 2021. 2. 4.
반응형