본문 바로가기

Algorithm/LEET CODE ( 파이썬 알고리즘 인터뷰)56

[LEET CODE] 200. Number of Islands # Problem Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. Constraints: m == grid.length n == grid[i].length 1 = len(grid) or \ j = len(grid[.. 2021. 4. 6.
[LEET CODE] 347. Top K Frequent Elements( zip 함수, * (아스테리스크)) # Problem Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Constraints: 1 List[int]: freqs = collections.Counter(nums) freqs_heap = [] # 힙에 음수로 삽입 for f in freqs: heapq.heappush(freqs_heap, (-freqs[f], f)) topk = list() # k번 만큼 추출, 민 힙 이므로 가장 작은 음수 순으로 추출 for _ in range(k): topk.append(heapq.heappop(freqs_heap)[1]) return .. 2021. 4. 5.
[LEET CODE] 3. Longest Substring Without Repeating Characters # Problem Given a string s, find the length of the longest substring without repeating characters. Constraints: 0 2021. 4. 5.
[LEET CODE] 771. Jewels and Stones # Problem You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels. Letters are case sensitive, so "a" is considered a different type of stone from "A". Constraints: 1 int: freqs = {} count = 0 # 돌(S)의 빈도 수 계산 for.. 2021. 4. 5.
[LEET CODE] 706. Design HashMap # Problem Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: MyHashMap() initializes the object with an empty map. void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value. int get(int key) returns the value to which the specified key is mapped, or -1 if this map c.. 2021. 4. 5.
❗️[LEET CODE] 23. Merge k Sorted Lists ( k개 정렬 리스트 병합) # Problem You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. Constraints: k == lists.length 0 2021. 4. 1.
반응형