목록MJ (709)
MJay
Do you know when we should use two stacks to implement a queue? I was asked in an internship interview with a company two years ago. The application for this implementation is to separate read & write of a queue in multi-processing. One of the stacks is for reading, and another is to write. They only interfere with each other when the former one is full or the latter is empty. Python에서는 Stack이 L..
215. Kth Largest Element in an Array Medium 2561196FavoriteShare Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: [3,2,1,5,6,4] and k = 2 Output: 5 Example 2: Input: [3,2,3,1,2,4,5,5,6] and k = 4 Output: 4 Note: You may assume k is always valid, 1 ≤ k ≤ array's length. 그냥 sorting 하면 된다.
1135. Connecting Cities With Minimum Cost Medium 1155FavoriteShare There are N cities numbered from 1 to N. You are given connections, where each connections[i] = [city1, city2, cost] represents the cost to connect city1 and city2 together. (A connection is bidirectional: connecting city1 and city2 is the same as connecting city2 and city1.) Return the minimum cost so that for every pair of citi..
1064. Fixed Point Easy 8429FavoriteShare Given an array A of distinct integers sorted in ascending order, return the smallest index i that satisfies A[i] == i. Return -1 if no such i exists. Example 1: Input: [-10,-5,0,3,7] Output: 3 Explanation: For the given array, A[0] = -10, A[1] = -5, A[2] = 0, A[3] = 3, thus the output is 3. Example 2: Input: [0,2,5,8,17] Output: 0 Explanation: A[0] = 0, t..
647. Palindromic Substrings Medium 173587FavoriteShare Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters. Example 1: Input: "abc" Output: 3 Explanation: Three palindromic strings: "a", "b", "c". Example 2: Input: "aaa" Output: 6 E..
241. Different Ways to Add Parentheses Medium 118661FavoriteShare Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *. Example 1: Input: "2-1-1" Output: [0, 2] Explanation: ((2-1)-1) = 0 (2-(1-1)) = 2 Example 2: Input: "2*3-4*5" Output: [-34, -14, -10, -10, 10] Expla..