Programming/LeetCode
3Sum
2021. 1. 12.문제 링크 : leetcode.com/problems/3sum/submissions/ 3Sum - 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 제공되는 배열의 수 중 3개를 골라 0이 되는 수의 조합을 return 한다. class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: nums.sort() result = [] for i in range(0, len(nums) - 2): left ..
Group Anagrams
2021. 1. 11.문제 링크 : leetcode.com/problems/group-anagrams/ Group Anagrams - 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 같은 글자로 이루어진 단어들(아나그램) 끼리 모아서 리스트로 넘겨준다. 조금 생각해보니 쉬운 해결 방법이 생각나서 그대로 풀었다. 방법은 단어를 정렬한 다음 key로 사용하는 것이다. 20분 정도 걸린 것 같다. class Solution: def groupAnagrams(self, strs: List[s..
Most Common Word
2021. 1. 10.문제 링크 : leetcode.com/problems/most-common-word/submissions/ paragraph 중에 banned와 특수문자를 뺀 단어 중에 가장 빈도가 많은 단어를 찾는 것이 목표다. 결국에 책을 보고 풀었는데 문제에서 함정? 이라고 할 수 있는 것이 str과 list의 단어 제거 문제이다. str.replace()를 사용하면 banned 문자가 "abc"일 때 abcd는 d가 남게된다. 그렇다고 split()으로 list를 만든 후 list.remove()를 하면 한 개만 지워진다. 찾아보니 filter를 이용해서 지울 수는 있겠지만 banned loop를 돌아야해서 비효율적이다. class Solution: # 틀린 답안. str, list의 제한된 remove가 발목을..
Reorder Data in Log Files
2021. 1. 10.문제 링크 : leetcode.com/problems/reorder-data-in-log-files/ 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 로그가 str인 리스트로 주어지고 str에 " "가 delimiter 다. 두 번째 값으로 정렬하는데 문자가 숫자보다 우선이다. 또한 숫자는 문자의 뒤로만 보낼뿐 정렬하지 않는다. 문자 정렬의 경우 앞의 identifier로 정렬한다. (이부분이 확실치가 않다) 리스..
Reverse String
2021. 1. 8.문제 링크 : 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 책 문자열 중 두번째 문제. 가장 쉽다. class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ s[:] = s[::-1] 책에 쓰여있듯이 s ..
Valid Palindrome
2021. 1. 8.문제 링크 : leetcode.com/problems/valid-palindrome/ Valid Palindrome - 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: def isPalindrome(self, s: str) -> bool: s = re.sub(r"[^a-zA-Z0..
Remove Duplicates from Sorted Array
2021. 1. 8.문제링크 : leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/727/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 알고리즘 책을 사서 보는 중이라 다 보기 전까지는 괜히 어려운거 풀어서 스트레스 받느니 하루에 한 두 문제씩 습관을 먼저 들이자는 생각이 들어 쉬운 문제..
Beautiful Arrangement (Fail)
2021. 1. 3.문제링크 : leetcode.com/explore/challenge/card/january-leetcoding-challenge-2021/579/week-1-january-1st-january-7th/3591/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 어제 노느라 못풀고 January LeetCoding Challenge 2021 3일차를 도전했..
Check Array Formation Through Concatenation
2021. 1. 2.문제링크 : leetcode.com/explore/challenge/card/january-leetcoding-challenge-2021/579/week-1-january-1st-january-7th/3589/ Account Login - 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 릿트코드를 막 시작하고 둘러보는데 재밌는게 있다. 한 달간 매일 내는 문제를 다 풀면 선물을 준다. 프리미엄 티켓을 사야 풀 수 있는 문제와 그냥 풀 수 있는 문제 두 개를 주는데..
Two Sum
2021. 1. 2.문제 링크 : leetcode.com/problems/two-sum/ Two Sum - 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 릿트코드를 하면 처음 풀어본다는 가장 쉬운 문제다. nums(List)와 target 숫자를 받아 nums의 연속된 두 수를 더해서 target을 만들면 그 index 두 개를 return하면 된다. 첫 답안 class Solution: def twoSum(self, nums: List[int], target: int) -> Li..