- 博客(197)
- 资源 (7)
- 收藏
- 关注
原创 Restore IP Addresses
Restore IP AddressesGiven a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135",
2017-05-30 17:09:17 309
原创 Clone Graph
Clone GraphClone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a s
2017-05-23 15:35:15 250
原创 Gas Station
Gas StationThere are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel fro
2017-05-23 14:53:50 362
原创 Lowest Common Ancestor of a Binary Tree
Lowest Common Ancestor of a Binary TreeGiven 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
2017-05-19 10:32:50 217
原创 Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->
2017-05-19 10:07:32 263
原创 Reverse Linked List II
Reverse Linked List IIReverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.N
2017-05-19 09:40:39 220
原创 Minimum Size Subarray Sum
Minimum Size Subarray SumGiven an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 ins
2017-05-16 22:12:20 205
原创 Merge Intervals
Merge IntervalsGiven a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].解析:排序再找区间代码:/** * Defini
2017-05-16 20:51:17 238
原创 Jump Game
Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.
2017-05-16 20:37:05 202
原创 Distinct Subsequences
Distinct SubsequencesGiven a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string b
2017-05-16 19:44:09 199
原创 Search for a Range
Search for a RangeGiven an array of integers 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
2017-05-16 15:50:01 197
原创 Course Schedule
Course ScheduleThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, w
2017-05-16 15:24:55 256
原创 Unique Substrings in Wraparound String
Unique Substrings in Wraparound StringConsider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabc
2017-05-15 21:52:50 231
原创 Construct Binary Tree from Preorder and Inorder Traversal
Construct Binary Tree from Preorder and Inorder TraversalGiven preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the t
2017-05-15 20:19:20 286
原创 Patching Array
Patching ArrayGiven a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n]inclusive can be formed by the sum of some elemen
2017-05-15 20:03:56 213
原创 Russian Doll Envelopes
Russian Doll EnvelopesYou have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the width and height of o
2017-05-14 17:19:56 526
原创 Frog Jump
Frog JumpA frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.
2017-05-14 16:37:26 273
原创 Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder TraversalGiven inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the
2017-05-14 15:47:32 203
原创 Palindrome Partitioning
Palindrome PartitioningGiven a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "a
2017-05-14 15:18:43 176
原创 Permutations II
Permutations IIGiven a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[ [1,1,
2017-05-14 14:45:17 275
原创 Partition List
Partition ListGiven a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of
2017-05-14 12:56:23 159
原创 Sliding Window Maximum
Sliding Window MaximumGiven an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Ea
2017-05-12 16:28:36 232
原创 Palindrome Linked List
Palindrome Linked ListGiven a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?Subscribe to see which companies asked this
2017-05-12 15:34:02 181
原创 Max Sum of Rectangle No Larger Than K
Max Sum of Rectangle No Larger Than KGiven a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k.Example:Give
2017-05-12 14:50:53 240
原创 Insertion Sort List
Insertion Sort ListSort a linked list using insertion sort.Subscribe to see which companies asked this question.解析:插入排序,注意指针的指向代码:/** * Definition for singly-linked list. * s
2017-05-12 10:51:04 162
原创 01 Matrix
01 MatrixGiven a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0Output:
2017-05-11 10:46:34 242
原创 Search in Rotated Sorted Array II
Search in Rotated Sorted Array IIFollow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose an array
2017-05-10 20:39:29 223
原创 Serialize and Deserialize Binary Tree
Serialize and Deserialize Binary TreeSerialization 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 transmi
2017-05-10 18:56:23 190
原创 Largest Divisible Subset
Largest Divisible SubsetGiven a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.
2017-05-10 15:51:38 214
原创 Pacific Atlantic Water Flow
Pacific Atlantic Water FlowGiven an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the "Pacific ocean" touches the left and top edges of the ma
2017-05-10 14:57:08 214
原创 Perfect Number
Perfect NumberWe define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n, write a function that returns tr
2017-05-09 22:37:27 191
原创 Group Anagrams
Group AnagramsGiven an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat
2017-05-09 22:12:36 203
原创 Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Subscribe to see which companies ask
2017-05-09 21:36:04 174
原创 Find All Anagrams in a String
Find All Anagrams in a StringGiven a string s and a non-empty string p, find all the start indices of p's anagrams in s.Strings consists of lowercase English letters only and the length of b
2017-05-09 21:10:41 328
原创 Binary Tree Zigzag Level Order Traversal
Binary Tree Zigzag Level Order TraversalGiven a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alte
2017-05-09 20:49:04 184
原创 Bitwise AND of Numbers Range
Bitwise AND of Numbers RangeGiven a range [m, n] where 0 For example, given the range [5, 7], you should return 4.Credits:Special thanks to @amrsaqr for adding this problem and creatin
2017-05-09 20:25:11 200
原创 Reverse Pairs
Reverse PairsGiven an array nums, we call (i, j) an important reverse pair if i and nums[i] > 2*nums[j].You need to return the number of important reverse pairs in the given array.E
2017-05-09 16:12:53 531
原创 Count of Smaller Numbers After Self
Count of Smaller Numbers After SelfYou are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller e
2017-05-09 11:05:12 164
原创 Range Sum Query - Mutable
Range Sum Query - MutableGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by updating the el
2017-05-09 11:01:55 167
原创 Freedom Trail
Freedom TrailIn the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom Trail Ring", and use the dial to spell a specific keyword in orde
2017-05-08 16:44:55 328
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人