본문 바로가기
반응형

알고리즘222

[알고리즘 ] 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.
[알고리즘] 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.
반응형