Zero to Hero
article thumbnail
230. Kth Smallest Element in a BST
Algorithm 2021. 5. 7. 09:46

Kth Smallest Element in a BST - 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. In-Order Traversal using Iteration class Solution: def kthSmallest(self, root: TreeNode, k: int) -> int: answers=[] def inorder(cur): global count if not cur: return inorder(cur.left) answers.append(..

739. Daily Temperatures
Algorithm 2021. 5. 6. 15:44

Daily Temperatures - 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. Monotone Stack from typing import * class Solution: def dailyTemperatures(self, T: List[int]) -> List[int]: index = [i for i in range(len(T))] new_list = list(map(lambda x, y: (x, y), index, T)) stack, answer =..

article thumbnail
78. Subsets
Algorithm 2021. 5. 6. 14:53

Subsets - 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. 내장 함수 사용 from itertools import combinations class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: answer=[] for length in range(len(nums)+1): for item in combinations(nums, length): answer.append(list(ite..

article thumbnail
1. Two Sum
Algorithm 2021. 5. 5. 21:20

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 1. Sliding Window class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: index_list = [i for i in range(len(nums))] new_nums = list(map(lambda x, y: (x, y), nums, index_list)) new_nums.sort() start, end..

article thumbnail
206. Reverse Linked List
Algorithm 2021. 5. 5. 21:18

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 1. Stack을 사용한 풀이 class Solution: def reverseList(self, head: ListNode) -> ListNode: if not head: return None stack = [] cur = head while cur: stack.append(cur) cur = cur.next new_head = stack.pop() cur = new_head..

article thumbnail
234. Palindrome Linked List
Algorithm 2021. 5. 4. 14:36

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 1. 단순한 풀이 class Solution: def isPalindrome(self, head: ListNode) -> bool: cur = head trace = [] while cur: trace.append(cur.val) cur = cur.next return trace == trace[::-1] 경로를 저장하고 경로와 뒤집은 경로가 같은지를 반환한다. 2. Po..