본문 바로가기
반응형

알고리즘211

[알고리즘] Check If Two String Arrays are Equivalent 포인트 1. string 을 합쳐서 비교를 할 수 있는가? 를 물어보는 문제 해결 방법은 간단하다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. cpp class Solution { public: bool arrayStringsAreEqual(vector& word1, vector& word2) { string a; for (auto ele1: word1){ a+=ele1; } string b; for(auto ele2: word2){ b+=ele2; } return a==b; } }; python class Solution: def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: return (''.join(w.. 2021. 1. 31.
[알고리즘] 짝지어 제거하기 포인트 1. 스택을 사용할 수 있는가? 정말 신기하게도 문자열을 다루는 것들에서는 Stack 을 많이 쓴다. c++/cpp #include #include #include using namespace std; int solution(string s) { int answer = 0; stack stack; for (int i = 0; i < s.size(); i++) { // 1. 스택이 비어 있거나 이전에 스택 top 의 값이 현재 s[i] 와 다르다면 push if (stack.empty() || stack.top() != s[i]) { stack.push(s[i]); } else { // 2. 스택 top 의 값이 현재 s[i]와 같다면 top 에 있는 값을 pop stack.pop(); } } //.. 2021. 1. 28.
[알고리즘 ] Concatenation of Consecutive Binary Numbers 포인트 1. 파이썬은 진법 변환이 엄청 편하며 long long 구별 필요 없이 int 를 사용하면 된다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp class Solution { public: int concatenatedBinary(int n) { long res = 0, mod = 1e9+7, len_of_curr = 0; for (int i = 1; i 2021. 1. 28.
[알고리즘] 완주하지 못한 선수 포인트 1.잘 구현을 할 수 있는가? 2. 해시를 이용하여 다시 구현을 해보았다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. #include #include #include #include using namespace std; string solution(vector participant, vector completion) { sort(participant.begin(), participant.end()); sort(completion.begin(), completion.end()); int num = 0; for(int i=0; i < participant.size(); i++){ if( participant[i] != completion[i]) return participant[i]; .. 2021. 1. 26.
반응형