LeetCode
文章平均质量分 74
dongbeier
这个作者很懒,什么都没留下…
展开
-
25 Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number of no...原创 2018-06-14 06:27:51 · 104 阅读 · 0 评论 -
106 Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, giveninorder = [9,3,15,20,7]postorder = [9,15,7,20...原创 2018-06-14 06:27:48 · 88 阅读 · 0 评论 -
71 Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you consider the case where path = "/../"?I原创 2018-06-14 06:27:38 · 142 阅读 · 0 评论 -
189 Rotate Array
Given an array, rotate the array to the right by k steps, where k is non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1,2,3,...原创 2018-06-14 06:27:34 · 103 阅读 · 0 评论 -
94 Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]Follow up: Recursive solution is trivial, could you do i...原创 2018-06-14 06:27:28 · 81 阅读 · 0 评论 -
15 3Sum
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not contain ...原创 2018-06-14 06:27:12 · 109 阅读 · 0 评论 -
387 First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note: You may assume...原创 2018-06-14 06:27:08 · 103 阅读 · 0 评论 -
567 Permutation in String
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string.Example ...原创 2018-06-14 06:27:04 · 167 阅读 · 0 评论 -
204 Count Primes
Count the number of prime numbers less than a non-negative number, n.Example:Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.给出要筛数值的范围n,找出{\displaystyle {...原创 2018-06-14 06:27:00 · 148 阅读 · 0 评论 -
28 Implement strStr()
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example 2:Input:...原创 2018-06-14 06:26:55 · 92 阅读 · 0 评论 -
165 Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0.You may assume that the version strings are non-empty and c...原创 2018-06-14 06:26:51 · 93 阅读 · 0 评论 -
124 Binary Tree Maximum Path Sum
Given a non-empty binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections...原创 2018-06-14 06:26:48 · 102 阅读 · 0 评论 -
258 Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.Example:Input: 38Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. ...原创 2018-06-14 06:26:44 · 126 阅读 · 0 评论 -
125 Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome.Example 1...原创 2018-06-14 06:26:39 · 118 阅读 · 0 评论 -
339 Nested List Weight Sum
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list -- whose elements may also be integers or other lists....原创 2018-05-11 01:10:20 · 166 阅读 · 0 评论 -
244 Shortest Word Distance II
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameters. How would you ...原创 2018-05-11 01:26:52 · 100 阅读 · 0 评论 -
364 Nested List Weight Sum II
Given a nested list of integers, return the sum of all integers in the list weighted by their depth.Each element is either an integer, or a list -- whose elements may also be integers or other lists.D...原创 2018-05-11 01:33:16 · 144 阅读 · 0 评论 -
170 Two Sum III - Data structure design
Design and implement a TwoSum class. It should support the following operations:add and find.add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which su...原创 2018-05-11 01:41:05 · 139 阅读 · 0 评论 -
256 Paint House
There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the ho...原创 2018-05-11 01:54:01 · 115 阅读 · 0 评论 -
156 Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the origin...原创 2018-05-11 02:05:46 · 212 阅读 · 0 评论 -
716 Max Stack
Design a max stack that supports push, pop, top, peekMax and popMax. push(x) -- Push element x onto stack.pop() -- Remove the element on top of the stack and return it.top() -- Get the element on the ...原创 2018-05-11 02:25:32 · 436 阅读 · 0 评论 -
366 Find Leaves of Binary Tree
Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps until the tree is empty.Example:Given binary tree 1 / \ 2 3 / \ ...原创 2018-05-11 02:34:51 · 166 阅读 · 0 评论 -
254 Factor Combinations
Numbers can be regarded as product of its factors. For example,8 = 2 x 2 x 2; = 2 x 4.Write a function that takes an integer n and return all possible combinations of its factors.Note: Each combina...原创 2018-05-11 02:40:53 · 219 阅读 · 0 评论 -
245 Shortest Word Distance III
This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as word2.Given a list of words and two words word1 and word2, return the shortest distance between the...原创 2018-05-11 02:46:12 · 145 阅读 · 0 评论 -
698 Partition to K Equal Sum Subsets
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into knon-empty subsets whose sums are all equal.Example 1:Input: nums = [4, 3, 2, 3, 5, 2, 1]...原创 2018-05-11 03:08:47 · 101 阅读 · 0 评论 -
205 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another char...原创 2018-05-13 07:32:41 · 98 阅读 · 0 评论 -
53 Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation: [...原创 2018-05-13 07:32:34 · 115 阅读 · 0 评论 -
297 Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be...原创 2018-05-13 07:32:28 · 276 阅读 · 0 评论 -
605 Can Place Flowers
Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.Given ...原创 2018-05-13 07:32:22 · 163 阅读 · 0 评论 -
65 Valid Number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to b原创 2018-05-13 07:33:01 · 188 阅读 · 0 评论 -
50 Pow(x, n)
Implement pow(x, n), which calculates x raised to the power n (xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, -2Output: 0.25...原创 2018-05-13 07:31:45 · 248 阅读 · 0 评论 -
149 Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.Example 1:Input: [[1,1],[2,2],[3,3]]Output: 3Explanation:^|| o| o| o +----------...原创 2018-05-13 07:31:37 · 240 阅读 · 0 评论 -
68 Text Justification
Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidthcharacters and is fully (left and right) justified.You should pack your words in a greedy approach...原创 2018-05-13 07:31:30 · 213 阅读 · 0 评论 -
277 Find the Celebrity
Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1people know him/her but he/sh...原创 2018-05-13 07:31:24 · 180 阅读 · 0 评论 -
102 Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \...原创 2018-05-13 07:31:17 · 100 阅读 · 0 评论 -
56 Merge Intervals
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps, mer...原创 2018-05-13 07:31:03 · 226 阅读 · 0 评论 -
187 Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Write...原创 2018-05-13 07:30:57 · 139 阅读 · 0 评论 -
152 Maximum Product Subarray
Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation: [2,3] has th...原创 2018-05-13 07:30:51 · 160 阅读 · 0 评论 -
236 Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v an...原创 2018-05-13 07:30:45 · 113 阅读 · 0 评论 -
34 Search for a Range
Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the tar...原创 2018-05-13 07:30:38 · 89 阅读 · 0 评论