반응형 Algorithms119 [알고리즘] 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. [알고리즘] Sqrt(x) 포인트 1. 제곱근을 구하는 방법을 알아보자 (파이썬 도대체넌 어디까지 쉬울 거니) 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. cpp class Solution { public: int mySqrt(int x) { return sqrt(x); } }; python class Solution: def mySqrt(self, x: int) -> int: return int(x**(1/2)) 2021. 1. 22. [알고리즘] 문자열 다루기 포인트 1. 기본적인 조건들을 잘 구현을 할 수 있는가? 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. #include #include using namespace std; bool solution(string s) { if(s.size()!=4&&s.size()!=6) return false; for(auto ele :s){ if(ele'9') return false; } return true; } python def solution(s): if not (len(s)==4 or len(s)==6): return False try: int(s) except: return False return True 2021. 1. 22. [알고리즘] Valid Parentheses 포인트 1. 짝을 맞추는 방법 항상 괄호 문제하면 떠올리는 것은 스택을 사용하여 짝을 맞추는 것이다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++ #include #include using namespace std; class Solution { public: bool isValid(string s) { stack stack; for(auto ele : s) { if(stack.empty()) stack.push(ele); if(stack.top()=='['&& ele==']'){ stack.pop(); continue; } if(stack.top()=='('&& ele==')'){ stack.pop(); continue; } if(stack.top()=='{'&& ele=='}'){.. 2021. 1. 21. 이전 1 ··· 21 22 23 24 25 26 27 ··· 30 다음 반응형