리트코드
-
[leetcode] 819. Most Common WordAlgorithm/1일 1코테 2021. 4. 28. 14:21
819. Most Common Word leetcode.com/problems/most-common-word/ Most Common Word - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 조건 1. 금지어는 제거할 것 2. 특수문자 제거할 것 3. 소문자 혹은 대문자로 통일할 것 나의 답 def mostCommonWord(self, paragraph: str, banned: List[str]) -> str: import re # 전처리 paragraph = ..
-
[leetcode] 937. Reorder Log FilesAlgorithm/1일 1코테 2021. 4. 28. 09:12
leetcode.com/problems/reorder-data-in-log-files/submissions/ Reorder Data in Log Files - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 로그를 재정렬 하는 문제 조건은 1. 문자가 숫자의 앞 2. 제일 앞 문자가 동일할 경우 식별자 순으로 나열 3. 숫자로그는 입력 순서대로 처음에 생각한 건 sort로 정렬시킨 다음에 문자/숫자 나누려고 했는데 그러면 숫자로그가 입력순이 아니게 됨 결국 하나하..
-
[leetcode] 344. Reverse StringAlgorithm/1일 1코테 2021. 4. 14. 19:56
문제 leetcode.com/problems/reverse-string/ Reverse String - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com return할 필요없이 s 안의 값만 변경하는 문제. 단, 새로운 list 생성 등을 하면 안되고 s 안에서만 변경해야 한다. 모범답안 class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s ..
-
[leetcode] 125.Valid PalindromeAlgorithm/1일 1코테 2021. 4. 14. 19:35
문제 입력 문자열이 팰린드롬인지 확인하는 문제 leetcode.com/problems/valid-palindrome/ # 내 답 class Solution: def isPalindrome(self, s: str) -> bool: p = '' # 전처리한 str 담아줄 변수 for i in s: if i.isalpha() or i.isdigit(): # 알파벳이거나 숫자일때만 i = i.lower() # 소문자로 바꿔준 뒤 더해줌 p += i p2 = p[::-1] # 팰린드롬인지 비교하기 위해 뒤집음 for i in range(len(p)): if p[i] != p2[i]: # 0번째부터 하나씩 출력해서 다르면 False return False return True isalpha() + isdigit()..
-
[🤷♀️ Leetcode] 509. Fibonascci NumberAlgorithm/1일 1코테 2020. 11. 9. 14:39
문제설명 피보나치 수를 구하라 leetcode.com/problems/fibonacci-number/submissions/ Fibonacci Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 class Solution: dp = collections.defaultdict(int) def fib(self, N: int) -> int: if N
-
[😭 LeetCode Python] 371. Sum of Two IntegersAlgorithm/1일 1코테 2020. 10. 27. 16:53
📌 문제 및 문제설명 371. Sum of Two Integers +, -을 이용하지 않고 합을 구하는 문제 leetcode.com/problems/sum-of-two-integers/ Sum of Two Integers - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 📌 풀이 # 전가산기를 이용한 풀이 def getSum(self, a: int, b: int) -> int: MASK = 0xFFFFFFFF #보수용 mask INT_MAX = 0x7FFFFFF..
-
[💕 LeetCode Python] 191. Number of 1 BitsAlgorithm/1일 1코테 2020. 10. 27. 15:28
📌 문제 및 문제풀이 leetcode.com/problems/number-of-1-bits/ Number of 1 Bits - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 📌 내 답 def hammingWeight(self, n: int) -> int: return bin(n).count('1') 📌 풀이 #비트연산 풀이 원래 값 & 원래 값 - 1 => 원래 값에서 1이 하나 빠진 값이 나옴 이걸 모든 값이 0이 될때까지 반복하면 count에 1의 총 갯수가..
-
[🤷♀️ LeetCode Python] 393. UTF-8 ValidationAlgorithm/1일 1코테 2020. 10. 27. 15:08
✍LeetCode✍ 393. UTF-8 Validation 문제 및 문제설명 UTF-8임을 검증하는 문제 leetcode.com/problems/utf-8-validation/ UTF-8 Validation - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 내가 쓴 풀이 노가다 했는데도 틀림!!! 밑에 에러가 발생한 후 걍 포기했다 ㅎ def validUtf8(self, data: List[int]) -> bool: data = [bin(i).replace('0..