본문 바로가기

Programming/LeetCode37

[LeetCode] Reverse Linked List https://leetcode.com/problems/reverse-linked-list/ Reverse Linked List - 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 연결 리스트를 뒤집으면 된다. 단순한 문젠데 뭔가 실제로 해보려니까 한동안 뇌 정지 왔다. 역시 아직 부족하다 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # se.. 2022. 3. 23.
[LeetCode] Broken Calculator https://leetcode.com/problems/broken-calculator/ Broken Calculator - 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 brokenCalc(self, startValue: int, target: int) -> int: q : Deque = collections.deque() q.append((startValue, 0)) whil.. 2022. 3. 23.
[LeetCode] Merge Two Sorted Lists https://leetcode.com/problems/merge-two-sorted-lists/ Merge Two Sorted Lists - 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. list1과 list2를 비교해 주면서 merge_list에 추가 2. 원소가 남은 친구들을 추가 # Definition for singly-linked list. # class ListNode: # def _.. 2022. 3. 23.
[LeetCode] Palindrome Linked List https://leetcode.com/problems/palindrome-linked-list/ Palindrome Linked List - 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 Deque를 활용하면 popleft도 O(1) 이므로 성능 향상 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self... 2022. 3. 23.
[LeetCode] Reverse String https://leetcode.com/problems/reverse-string/submissions/ 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. """ left, right = 0,.. 2022. 2. 28.
[LeetCode] Valid Palindrome https://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 유효한 펠린드롬인지 확인하는 문제 Deque를 활용해서 풀이 가능 class Solution: def isPalindrome(self, s: str) -> bool: strs: Deque = collections.deque() for char in s: if char.isalnum(): strs.a.. 2022. 2. 25.
[LeetCode] Two Sum https://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 Leet Code의 문제들을 풀어 볼 예정이다. 처음 문제인 Two Sum 문제를 풀어봤다. 예전 화이트보드 코딩 테스트때 이 문제를 접한 적이 있었는데, 이렇게 유명한 문제인지 몰랐다. 그 때는 잘 못 풀었는데.. 이 문제는 dict 를 사용하면 O(n) 으로 풀이할 수 있다. 나의 풀이 class Solution: def tw.. 2022. 2. 9.