반응형 알고리즘222 [알고리즘] 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. [알고리즘] How Many Numbers Are Smaller Than the Current Number 포인트 1. 뭔가 조금 더 효율 적인 코드가 있을 것 같다. 해시로 풀기는 하였지만 어딘가 찜찜하다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp #include using namespace std; class Solution { public: vector smallerNumbersThanCurrent(vector& nums) { unordered_map map; unordered_set s(nums.begin(), nums.end()); for(auto ele1 : s){ for(auto ele2 : nums){ if(ele2 < ele1) map[ele1]++; } } vector answer; for(auto ele : nums){ answer.push_back(map[e.. 2021. 2. 4. [알고리즘] Find All Numbers Disappeared in an Array 포인트 1. 이번 문제는 MAP 을 이용하여 해결하는 문제입니다. MAP 을 해시의 개념으로 이해하여 생각하시면 정말 좋을 것 같습니다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp #include using namespace std; class Solution { public: int firstUniqChar(string s) { unordered_map map; for (auto ele : s) { map[ele]++; } for (int i = 0; i .. 2021. 2. 4. [알고리즘] Count Primes 어느 순간 300명이 제 부족한 글을 읽어주셔서 다시 한번 감사드립니다. 앞으로도 꾸준히 하는 개발자가 되겠습니다. 강한 놈이 살아남느게 아니라 살아남는 놈이 강한거다. 포인트 1. 이번 문제는 소수 찾기를 하는 문제 입니다. 소수를 찾는 방법은 여러가지가 있으나 제일 유명한 것은 에라토네스 체가 아닐까 싶습니다.. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp class Solution { public: int countPrimes(int n) { bool isPrime[5000000]; for (int i = 2; i < n; i++) { isPrime[i] = true; } // Loop's ending condition is i * i < n instead of i < s.. 2021. 2. 4. 이전 1 ··· 21 22 23 24 25 26 27 ··· 56 다음 반응형