- 博客(197)
- 资源 (7)
- 收藏
- 关注
原创 Restore IP Addresses
Restore IP Addresses Given 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 294
原创 Clone Graph
Clone Graph Clone 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 237
原创 Gas Station
Gas Station There 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 350
原创 Lowest Common Ancestor of a Binary Tree
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
2017-05-19 10:32:50 209
原创 Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II Given 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 252
原创 Reverse Linked List II
Reverse Linked List II Reverse 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 209
原创 Minimum Size Subarray Sum
Minimum Size Subarray Sum Given 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 197
原创 Merge Intervals
Merge Intervals Given 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 229
原创 Jump Game
Jump Game Given 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 191
原创 Distinct Subsequences
Distinct Subsequences Given 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 188
原创 Search for a Range
Search for a Range Given 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 186
原创 Course Schedule
Course Schedule There 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 247
原创 Unique Substrings in Wraparound String
Unique Substrings in Wraparound String Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabc
2017-05-15 21:52:50 218
原创 Construct Binary Tree from Preorder and Inorder Traversal
Construct Binary Tree from Preorder and Inorder Traversal Given 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 277
原创 Patching Array
Patching Array Given 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 204
原创 Russian Doll Envelopes
Russian Doll Envelopes You 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 503
原创 Frog Jump
Frog Jump A 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 252
原创 Construct Binary Tree from Inorder and Postorder Traversal
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
2017-05-14 15:47:32 190
原创 Palindrome Partitioning
Palindrome Partitioning Given 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 158
原创 Permutations II
Permutations II Given 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 260
原创 Partition List
Partition List Given 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 146
原创 Sliding Window Maximum
Sliding Window Maximum Given 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 221
原创 Palindrome Linked List
Palindrome Linked List Given 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 170
原创 Max Sum of Rectangle No Larger Than K
Max Sum of Rectangle No Larger Than K Given 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 225
原创 Insertion Sort List
Insertion Sort List Sort 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 151
原创 01 Matrix
01 Matrix Given 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 0 0 1 0 0 0 0 Output:
2017-05-11 10:46:34 229
原创 Search in Rotated Sorted Array II
Search in Rotated Sorted Array II Follow 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 216
原创 Serialize and Deserialize Binary Tree
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 transmi
2017-05-10 18:56:23 174
原创 Largest Divisible Subset
Largest Divisible Subset Given 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 200
原创 Pacific Atlantic Water Flow
Pacific Atlantic Water Flow Given 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 203
原创 Perfect Number
Perfect Number We 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 178
原创 Group Anagrams
Group Anagrams Given 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 189
原创 Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search Tree Given 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 162
原创 Find All Anagrams in a String
Find All Anagrams in a String Given 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 317
原创 Binary Tree Zigzag Level Order Traversal
Binary Tree Zigzag Level Order Traversal Given 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 175
原创 Bitwise AND of Numbers Range
Bitwise AND of Numbers Range Given 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 188
原创 Reverse Pairs
Reverse Pairs Given 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 519
原创 Count of Smaller Numbers After Self
Count of Smaller Numbers After Self You 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 152
原创 Range Sum Query - Mutable
Range Sum Query - Mutable Given 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 156
原创 Freedom Trail
Freedom Trail In 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 316
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人