leetcode.com/problems/palindrome-partitioning/ 백트랙킹과 리스트 구성 및 리턴 방식을 눈여겨 볼만한 문제. 시리즈 문제도 같이 풀어보자: inner-game.tistory.com/458 131. Palindrome Partitioning Medium 257384Add to ListShare Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. A palindrome string is a string that reads the same backward as forward. E..
Binary Indexed Tree 프리퀀시 정렬 이지가 하나도 없네 #TitleTagsAcceptanceDifficultyFrequency 315 Count of Smaller Numbers After Self Binary SearchDivide and ConquerSortBinary Indexed TreeSegment TreeGoogle 42.4% Hard 493 Reverse Pairs Binary SearchDivide and ConquerSortBinary Indexed TreeSegment TreeGoogle 26.2% Hard 218 The Skyline Problem Divide and ConquerHeapBinary Indexed TreeSegment TreeLine SweepGoogle..
frequency 로 정렬함 843 Guess the Word Minimax Google 46.4% 913 Cat and Mouse Breadth-first Search Minimax Google 33.8% 486 Predict the Winner Dynamic Programming Minimax Google 48.4% 877 Stone Game Math Dynamic Programming Minimax 66.1% 292 Nim Game Brainteaser Minimax Adobe 54.9% 375 Guess Number Higher or Lower II Dynamic Programming Minimax Google 41.6% 464 Can I Win Dynamic Programming Minimax ..
leetcode.com/problems/burst-balloons/ 312. Burst Balloons Hard 297379Add to ListShare Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[left] * nums[i] * nums[right] coins. Here left and right are adjacent indices of i. After the burst, the left and ..
877 Stone Game 66.1% Math, DP, MiniMax 1140 Stone Game II 64.9% DP 1406 Stone Game III 56.9% DP 1510 Stone Game IV 58.6% DP 1563 Stone Game V 40.1% DP 1686 Stone Game VI 38.5% Greedy leetcode.com/problems/stone-game/ 877. Stone Game leetcode.com/problems/stone-game-ii/ 1140. Stone Game II leetcode.com/problems/stone-game-iii/ 1406. Stone Game III leetcode.com/problems/stone-game-iv/ 1510. Stone ..
leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/ Medium 1013272Add to ListShare Given the root of a binary tree, the depth of each node is the shortest distance to the root. Return the smallest subtree such that it contains all the deepest nodes in the original tree. A node is called the deepest if it has the largest depth possible among any node in the entire tree. The subtree..
leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 2번 방법으로 풀어야함. Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra space for another array; you must do this by modifying the input array in-place with O(1) extra memory. Clarification: Confused why the returned value is an integer, but y..
리트코드 미로찾기 maze 총정리 leetcode.com/problemset/all/?search=maze leetcode.com/problems/the-maze/ 490. The Maze Medium 920104Add to ListShare There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the nex..
leetcode.com/problems/valid-mountain-array/ 941. Valid Mountain Array Easy 57981Add to ListShare Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if: arr.length >= 3 There exists some i with 0 arr[i + 1] > ... > arr[arr.length ..
leetcode.com/problems/binary-search-tree-iterator/ 1번과 2번은 공간복잡도에서 차이가 있기 때문에 2번을 선택해야한다. 1번은 모든 노드를 저장하고 2번은 노드의 높이만큼 저장한다. 물론 기울어진 트리의 경우에는 같다. 173. Binary Search Tree Iterator Medium 3097288Add to ListShare Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTIterator c..
leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/ 1010. Pairs of Songs With Total Durations Divisible by 60 Medium 75962Add to ListShare You are given a list of songs where the ith song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that..
leetcode.com/problems/missing-ranges/ You are given an inclusive range [lower, upper] and a sorted unique integer array nums, where all elements are in the inclusive range. A number x is considered missing if x is in the range [lower, upper] and x is not in nums. Return the smallest sorted list of ranges that cover every missing number exactly. That is, no element of nums is in any of the ranges..
leetcode.com/problems/spiral-matrix-ii/ Spiral Matrix II - 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 Overview There are various problems in spiral matrix series with some variations like Spiral Matrix and Spiral Matrix III. In order to solve such questions, the core idea is t..
leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/ Populating Next Right Pointers in Each Node II - 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 솔루션2로 풀도록 할것. Given a binary treestruct Node { int val; Node *left; Node *right; Node *next; } Populate each next p..
leetcode.com/problems/can-place-flowers/ Can Place Flowers - 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 문제는 쉽다. and 와 or을 잘 이해하고, 조건문을 얼마나 아름답게 쓰냐의 차이.. public class Solution { public boolean canPlaceFlowers(int[] flowerbed, int n) { int i = 0, count = 0; while (i < flowerbed...
leetcode.com/problems/maximum-depth-of-binary-tree/ 보통 마지막 솔루션이 더 옵티멀한거여서 봤는데, 특별한것이 없었다; Approach 1: Recursion Intuition By definition, the maximum depth of a binary tree is the maximum number of steps to reach a leaf node from the root node. From the definition, an intuitive idea would be to traverse the tree and record the maximum depth during the traversal. Algorithm 1 / 10 One could travers..
leetcode.com/problems/shortest-word-distance/ n^2으로 풀면 안된다. class Solution { public int shortestDistance(String[] words, String word1, String word2) { int i1 = -1, i2 = -1; int minDistance = words.length; for (int i = 0; i < words.length; i++) { if (words[i].equals(word1)) { i1 = i; } else if (words[i].equals(word2)) { i2 = i; } if (i1 != -1 && i2 != -1) { minDistance = Math.min(minDistance, Mat..
leetcode.com/problems/the-kth-factor-of-n/ The kth Factor of n - 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 금요일이라고 쉬운문제인건가 싶었지만, 그렇지 않았음 In this article, we consider three solutions. Approach 1: Brute Force, \mathcal{O}(N)O(N). One could iterate from 11 to NN, figure out all d..
leetcode.com/problems/min-cost-climbing-stairs/ Min Cost Climbing Stairs - 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 { public int minCostClimbingStairs(int[] cost) { int f1 = 0, f2 = 0; for(int i = cost.length - 1; i >= 0; --i) { int f0 = cost[i] + Math.min(f1,..
leetcode.com/problems/increasing-order-search-tree/ Increasing Order Search Tree - 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 Approach 1: In-Order Traversal class Solution { public TreeNode increasingBST(TreeNode root) { List vals = new ArrayList(); inorder(root, vals); TreeNo..
leetcode.com/problems/random-pick-index/ Random Pick Index - 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 Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array...
www.geeksforgeeks.org/reservoir-sampling/ Reservoir Sampling - GeeksforGeeks A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. www.geeksforgeeks.org leetcode.com/problems/linked-list-random-node/ Linked List Random Node - LeetCode Level..
Design a queue that supports push and pop operations in the front, middle, and back. Implement the FrontMiddleBack class: FrontMiddleBack() Initializes the queue. void pushFront(int val) Adds val to the front of the queue. void pushMiddle(int val) Adds val to the middle of the queue. void pushBack(int val) Adds val to the back of the queue. int popFront() Removes the front element of the queue a..
leetcode.com/problems/range-sum-of-bst/ Range Sum of 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 youtu.be/3XmV2XzJrw0 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { thi..
class Solution { public int minimumDeletions(String s) { int n = s.length(); int[] aCnt = new int[n+1]; for(int i = n-1; i >= 0; i--) { aCnt[i] = aCnt[i+1]; if(s.charAt(i) == 'a') aCnt[i]++; } int delection = aCnt[0]; int bCnt = 0; for(int i = 0; i < n; i++) { if(s.charAt(i) == 'b') bCnt++; delection = Math.min(delection, bCnt + aCnt[i+1]); } return delection; } } 스택을 이용하는 다른 방법도 있음.
구글꺼에 HARD 가 많아보이는건 내 착각인가...
en.wikipedia.org/wiki/Practice_(learning_method)#Deliberate_practice Practice (learning method) - Wikipedia From Wikipedia, the free encyclopedia Jump to navigation Jump to search The act of rehearsing a behavior repeatedly; sessions scheduled for the purpose of rehearsing and performance improvement Practice is the act of rehearsing a behaviour over and over, o en.wikipedia.org tackleberrysolut..
Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times). Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again). Example 1: Input: [7..
class Solution { public int findMaxConsecutiveOnes(int[] nums) { int maxHere = 0, max = 0; for (int n : nums) max = Math.max(max, maxHere = n == 0 ? 0 : maxHere + 1); return max; } } Max Consecutive Ones Solution Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are c..