Zero to Hero
article thumbnail
347. Top K Frequent Elements
Algorithm 2021. 5. 8. 22:07

Top K Frequent Elements - 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. Using Counter from typing import * from collections import Counter class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: counter_dict = Counter() for num in nums: counter_dict[num] ..

article thumbnail
647. Palindromic Substrings
Algorithm 2021. 5. 7. 11:21

Palindromic Substrings - 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. Brute Force (실패) class Solution: def countSubstrings(self, s: str) -> int: def check(input_string): start, end = 0, len(input_string) - 1 while start < end: if input_string[start] != input_string[end]: retu..

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..