
Leetcode
糕冷羊
这个作者很懒,什么都没留下…
展开
-
LeetCode之Projection Area of 3D Shapes(Kotlin)
问题:On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes.Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j).Now we v...原创 2018-12-23 21:38:17 · 231 阅读 · 0 评论 -
LeetCode之Increasing Order Search Tree(Kotlin)
问题:Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only 1 right child.Example 1:Input: [5,3,6,...原创 2018-12-15 18:09:28 · 211 阅读 · 0 评论 -
LeetCode之Reveal Cards In Increasing Order(Kotlin)
问题:In a deck of cards, every card has a unique integer. You can order the deck in any order you want.Initially, all the cards start face down (unrevealed) in one deck.Now, you do the following st...原创 2018-12-08 21:21:52 · 234 阅读 · 0 评论 -
LeetCode之DI String Match(Kotlin)
问题:Given a string S that only contains “I” (increase) or “D” (decrease), let N = S.length.Return any permutation A of [0, 1, …, N] such that for all i = 0, …, N-1:If S[i] == “I”, then A[i] < A...原创 2018-12-01 20:18:40 · 482 阅读 · 0 评论 -
LeetCode之Delete Columns to Make Sorted(Kotlin)
问题:We are given an array A of N lowercase letter strings, all of the same length.Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices. ...原创 2018-11-25 00:45:59 · 257 阅读 · 0 评论 -
LeetCode之Minimum Add to Make Parentheses Valid(Kotlin)
问题:Given a string S of ‘(’ and ‘)’ parentheses, we add the minimum number of parentheses ( ‘(’ or ‘)’, and in any positions ) so that the resulting parentheses string is valid.Formally, a parenthes...原创 2018-11-18 01:40:19 · 216 阅读 · 0 评论 -
LeetCode之Range Sum of BST(Kotlin)
问题:Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive).The binary search tree is guaranteed to have unique values.Example 1:...原创 2018-11-14 23:12:17 · 424 阅读 · 0 评论 -
LeetCode之Unique Email Addresses(Kotlin)
问题:Every email consists of a local name and a domain name, separated by the @ sign.For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name.Besides lowercas...原创 2018-11-04 23:39:25 · 761 阅读 · 0 评论 -
LeetCode之Middle of the Linked List(Kotlin)
问题:Given a non-empty, singly linked list with head node head, return a middle node of linked list.If there are two middle nodes, return the second middle node.Example 1:Input: [1,2,3,4,5]Outpu...原创 2018-10-27 22:13:28 · 302 阅读 · 0 评论 -
LeetCode之Insert into a Binary Search Tree(Kotlin)
问题:Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed th...原创 2018-10-20 18:26:26 · 219 阅读 · 0 评论 -
LeetCode之Sort Array By Parity II(Kotlin)
问题:Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even.Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, ...原创 2018-10-14 16:17:33 · 325 阅读 · 0 评论 -
LeetCode之Search in a Binary Search Tree(Kotlin)
问题:Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node’s value equals the given value. Return the subtree rooted with that node. If such...原创 2018-10-08 19:46:08 · 136 阅读 · 0 评论 -
LeetCode之Partition Labels(Kotlin)
问题:A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representi...原创 2018-10-06 16:27:32 · 254 阅读 · 0 评论 -
LeetCode之Sort Array By Parity(Kotlin)
问题:Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A.You may return any answer array that satisfies this con...原创 2018-09-22 18:51:03 · 257 阅读 · 0 评论 -
LeetCode之All Paths From Source to Target(Kotlin)
问题: Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N-1, and return them in any order. The graph is given as follows: the nodes are 0, 1, …, graph.le...原创 2018-09-16 13:32:32 · 176 阅读 · 0 评论 -
LeetCode之Peak Index in a Mountain Array(Kotlin)
问题: Let’s call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < … A[i-1] < A[i] > A...原创 2018-09-10 13:52:02 · 226 阅读 · 0 评论 -
LeetCode之Flipping an Image(Kotlin)
问题: Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed...原创 2018-09-05 14:34:18 · 152 阅读 · 0 评论 -
LeetCode之Unique Morse Code Words(Kotlin)
问题: International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: “a” maps to “.-“, “b” maps to “-…”, “c” maps to “-.-.”, and so on...原创 2018-08-25 22:14:15 · 159 阅读 · 0 评论 -
LeetCode之Find and Replace Pattern(Kotlin)
问题: You have a list of words and a pattern, and you want to know which words in words matches the pattern. A word matches the pattern if there exists a permutation of letters p so that after ...原创 2018-08-20 15:12:37 · 193 阅读 · 0 评论 -
LeetCode之Binary Tree Pruning(Kotlin)
问题: We are given the head node root of a binary tree, where additionally every node’s value is either a 0 or a 1. Return the same tree where every subtree (of the given tree) not containing a...原创 2018-08-18 14:36:24 · 178 阅读 · 0 评论 -
LeetCode之Score After Flipping Matrix(Kotlin)
问题: We have a two dimensional matrix A where each value is 0 or 1. A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all...原创 2018-08-12 22:48:51 · 186 阅读 · 0 评论 -
LeetCode之To Lower Case(Kotlin)
问题: Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.方法: 这个应该不用说了吧,直接看代码。具体实现:class ToLowerCase { fun toLowerCase(str: Str...原创 2018-08-04 00:34:18 · 598 阅读 · 0 评论 -
LeetCode之Max Increase to Keep City Skyline(Kotlin)
问题: In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located there. We are allowed to increase the height of any number of buildings, by any amount (the a...原创 2018-07-28 14:23:00 · 188 阅读 · 0 评论 -
LeetCode之Jewels and Stones(Kotlin)
问题: You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many ...原创 2018-02-08 17:50:03 · 390 阅读 · 0 评论 -
LeetCode之Prime Number of Set Bits in Binary Representation(Kotlin)
问题: Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation. (Recall that the number of set bits原创 2018-01-28 19:19:33 · 205 阅读 · 0 评论 -
LeetCode之Find Anagram Mappings(Kotlin)
问题: Given two lists Aand B, and B is an anagram of A. B is an anagram of A means B is made by randomizing the order of the elements in A. We want to find an index mapping P, from A to B. A mapp原创 2018-01-20 21:02:17 · 211 阅读 · 0 评论 -
LeetCode之Find Largest Value in Each Tree Row(Kotlin)
问题: You need to find the largest value in each row of a binary tree. Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]方法: 递归实现,遍历所有节点,递归时传递层级,利用map在同一层级保存最大的数值,最后输出m原创 2018-01-13 15:50:03 · 167 阅读 · 0 评论 -
LeetCode之Sum of Left Leaves(Kotlin)
问题: Find the sum of all left leaves in a given binary tree. 3 / \9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.方法: 递归实现,遍历所原创 2018-01-07 12:22:53 · 140 阅读 · 0 评论 -
LeetCode之Convert BST to Greater Tree(Kotlin)
问题: Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.方原创 2017-12-30 15:23:02 · 165 阅读 · 0 评论 -
LeetCode之Construct String from Binary Tree(Kotlin)
问题: You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to be represented by empty parenthesis pair “()”原创 2017-12-26 23:43:41 · 170 阅读 · 0 评论 -
LeetCode之Two Sum IV - Input is a BST(Kotlin)
问题: Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.方法: 与TwoSum的解法差不多,不过需要在其中加入树的遍历,深度优先遍历和广度优先遍原创 2017-12-23 11:51:16 · 162 阅读 · 0 评论 -
LeetCode之1-bit and 2-bit Characters(Kotlin)
问题: We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). Now given a string represented by severa原创 2017-12-22 14:03:16 · 181 阅读 · 0 评论 -
LeetCode之Find Smallest Letter Greater Than Target(Kotlin)
问题: Given a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list that is larger than the given target. Lett原创 2017-12-20 23:32:47 · 360 阅读 · 2 评论 -
LeetCode之Find All Numbers Disappeared in an Array(Kotlin)
问题: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this arra原创 2017-12-19 23:44:42 · 136 阅读 · 0 评论 -
LeetCode之Count Binary Substrings(Kotlin)
问题: Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0’s and 1’s, and all the 0’s and all the 1’s in these substrings are grouped consecutively.原创 2017-12-16 16:24:33 · 228 阅读 · 0 评论