반응형 알고리즘211 [알고리즘] 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. [알고리즘] Goal Parser Interpretation 포인트 1. 그냥 떠올리는 거 편한거를 쓰는 것이 좋을 것 같다. 공부할때는 어렵게 할때는 쉽게포인트 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp class Solution { public: string interpret(string command) { stack st; string result; for(auto ele : command){ if(ele=='G'){ result+=ele; continue; } if(ele=='('){ st.push(ele); continue; } if(st.top()=='(' && ele == ')'){ st.pop(); result+='o'; continue; } if(st.top()=='l'&& ele==')'){ st.pop(); st.p.. 2021. 2. 1. [알고리즘] Count the Number of Consistent Strings 포인트 1. 연관되어 있는 단어, 포함되어 있는 단어를 찾는 문제, 적절히 set과 map 을 사용하여 해결하자 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp #include using namespace std; class Solution { public: int countConsistentStrings(string allowed, vector &words) { int count = 0; for(auto ele1: words){ unordered_set set(ele1.begin(), ele1.end()); for(auto ele2 : set){ if(allowed.find(ele2)==string::npos){ count+=1; break; } } } return words.s.. 2021. 1. 31. 이전 1 ··· 21 22 23 24 25 26 27 ··· 53 다음 반응형