leetcode 150道題目的原題
阿新 • • 發佈:2018-12-24
leetcode 的150道題目,用指令碼匯出的,方便平時練習。
1:https://oj.leetcode.com/problems/reverse-words-in-a-string/
name:Reverse Words in a String date:2014-03-05 rate:14.0%Reverse Words in a String Total Accepted: 34174 Total Submissions: 244099 My Submissions
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". click to show clarification. Clarification: What constitutes a word? A sequence of non-space characters constitutes a word. Could the input string contain leading or trailing spaces? Yes. However, your reversed string should not contain leading or trailing spaces. How about multiple spaces between two words? Reduce them to a single space in the reversed string.
-----------------------------------------------
2:https://oj.leetcode.com/problems/evaluate-reverse-polish-notation/
name:Evaluate Reverse Polish Notation date:2013-11-27 rate:19.8%
Evaluate Reverse Polish Notation Total Accepted: 24966 Total Submissions: 125931 My Submissions
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples:
["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9
["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6
-----------------------------------------------
3:https://oj.leetcode.com/problems/max-points-on-a-line/
name:Max Points on a Line date:2013-11-22 rate:11.0%
Max Points on a Line Total Accepted: 19925 Total Submissions: 181591 My Submissions
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
-----------------------------------------------
4:https://oj.leetcode.com/problems/sort-list/
name:Sort List date:2013-11-16 rate:20.5%
Sort List Total Accepted: 21918 Total Submissions: 107028 My Submissions
Sort a linked list in O(n log n) time using constant space complexity.
-----------------------------------------------
5:https://oj.leetcode.com/problems/insertion-sort-list/
name:Insertion Sort List date:2013-11-12 rate:25.3%
Insertion Sort List Total Accepted: 22390 Total Submissions: 88577 My Submissions
Sort a linked list using insertion sort.
-----------------------------------------------
6:https://oj.leetcode.com/problems/lru-cache/
name:LRU Cache date:2013-11-09 rate:14.0%
LRU Cache Total Accepted: 18525 Total Submissions: 131928 My Submissions
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1. set(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
-----------------------------------------------
7:https://oj.leetcode.com/problems/binary-tree-postorder-traversal/
name:Binary Tree Postorder Traversal date:2013-11-07 rate:31.0%
Binary Tree Postorder Traversal Total Accepted: 31462 Total Submissions: 101562 My Submissions
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3},
1
\
2
/
3
return [3,2,1]. Note: Recursive solution is trivial, could you do it iteratively?
-----------------------------------------------
8:https://oj.leetcode.com/problems/binary-tree-preorder-traversal/
name:Binary Tree Preorder Traversal date:2013-11-05 rate:35.7%
Binary Tree Preorder Traversal Total Accepted: 34769 Total Submissions: 97338 My Submissions
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3},
1
\
2
/
3
return [1,2,3]. Note: Recursive solution is trivial, could you do it iteratively?
-----------------------------------------------
9:https://oj.leetcode.com/problems/reorder-list/
name:Reorder List date:2013-11-02 rate:20.3%
Reorder List Total Accepted: 20667 Total Submissions: 101652 My Submissions
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For example, Given {1,2,3,4}, reorder it to {1,4,2,3}.
-----------------------------------------------
10:https://oj.leetcode.com/problems/linked-list-cycle-ii/
name:Linked List Cycle II date:2013-10-30 rate:30.9%
Linked List Cycle II Total Accepted: 23019 Total Submissions: 74473 My Submissions
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space?
-----------------------------------------------
11:https://oj.leetcode.com/problems/linked-list-cycle/
name:Linked List Cycle date:2013-10-28 rate:35.9%
Linked List Cycle Total Accepted: 31351 Total Submissions: 87303 My Submissions
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space?
-----------------------------------------------
12:https://oj.leetcode.com/problems/word-break-ii/
name:Word Break II date:2013-10-05 rate:16.5%
Word Break II Total Accepted: 16230 Total Submissions: 98407 My Submissions
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, given s = "catsanddog", dict = ["cat", "cats", "and", "sand", "dog"]. A solution is ["cats and dog", "cat sand dog"].
-----------------------------------------------
13:https://oj.leetcode.com/problems/word-break/
name:Word Break date:2013-10-04 rate:21.2%
Word Break Total Accepted: 23804 Total Submissions: 112362 My Submissions
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s = "leetcode", dict = ["leet", "code"]. Return true because "leetcode" can be segmented as "leet code".
-----------------------------------------------
14:https://oj.leetcode.com/problems/copy-list-with-random-pointer/
name:Copy List with Random Pointer date:2013-10-03 rate:23.3%
Copy List with Random Pointer Total Accepted: 19943 Total Submissions: 85594 My Submissions
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list.
-----------------------------------------------
15:https://oj.leetcode.com/problems/single-number-ii/
name:Single Number II date:2013-10-02 rate:33.9%
Single Number II Total Accepted: 26495 Total Submissions: 78211 My Submissions
Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
-----------------------------------------------
16:https://oj.leetcode.com/problems/single-number/
name:Single Number date:2013-10-01 rate:46.0%
Single Number Total Accepted: 36191 Total Submissions: 78760 My Submissions
Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
-----------------------------------------------
17:https://oj.leetcode.com/problems/candy/
name:Candy date:2013-09-30 rate:19.0%
Candy Total Accepted: 18708 Total Submissions: 98268 My Submissions
There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more candies than their neighbors. What is the minimum candies you must give?
-----------------------------------------------
18:https://oj.leetcode.com/problems/gas-station/
name:Gas Station date:2013-09-28 rate:25.8%
Gas Station Total Accepted: 20642 Total Submissions: 80061 My Submissions
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 from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations. Return the starting gas station's index if you can travel around the circuit once, otherwise return -1. Note: The solution is guaranteed to be unique.
-----------------------------------------------
19:https://oj.leetcode.com/problems/clone-graph/
name:Clone Graph date:2013-09-24 rate:22.9%
Clone Graph Total Accepted: 17542 Total Submissions: 76721 My Submissions
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 separator for each node, and , as a separator for node label and each neighbor of the node. As an example, consider the serialized graph {0,1,2#1,2#2,2}. The graph has a total of three nodes, and therefore contains three parts as separated by #. First node is labeled as 0. Connect node 0 to both nodes 1 and 2. Second node is labeled as 1. Connect node 1 to node 2. Third node is labeled as 2. Connect node 2 to node 2 (itself), thus forming a self-cycle. Visually, the graph looks like the following:
1
/ \
/ \
0 --- 2
/ \
\_/
-----------------------------------------------
20:https://oj.leetcode.com/problems/palindrome-partitioning-ii/
name:Palindrome Partitioning II date:2013-02-28 rate:18.2%
Palindrome Partitioning II Total Accepted: 15945 Total Submissions: 87765 My Submissions
Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s = "aab", Return 1 since the palindrome partitioning ["aa","b"] could be produced using 1 cut.
-----------------------------------------------
21:https://oj.leetcode.com/problems/palindrome-partitioning/
name:Palindrome Partitioning date:2013-02-27 rate:26.0%
Palindrome Partitioning Total Accepted: 19334 Total Submissions: 74357 My Submissions
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 = "aab", Return
[
["aa","b"],
["a","a","b"]
]
-----------------------------------------------
22:https://oj.leetcode.com/problems/surrounded-regions/
name:Surrounded Regions date:2013-02-21 rate:14.2%
Surrounded Regions Total Accepted: 13936 Total Submissions: 98021 My Submissions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region. For example,
X X X X
X O O X
X X O X
X O X X
After running your function, the board should be:
X X X X
X X X X
X X X X
X O X X
-----------------------------------------------
23:https://oj.leetcode.com/problems/sum-root-to-leaf-numbers/
name:Sum Root to Leaf Numbers date:2013-02-18 rate:29.7%
Sum Root to Leaf Numbers Total Accepted: 21998 Total Submissions: 74086 My Submissions
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers. For example,
1
/ \
2 3
The root-to-leaf path 1->2 represents the number 12. The root-to-leaf path 1->3 represents the number 13. Return the sum = 12 + 13 = 25.
-----------------------------------------------
24:https://oj.leetcode.com/problems/longest-consecutive-sequence/
name:Longest Consecutive Sequence date:2013-02-13 rate:28.2%
Longest Consecutive Sequence Total Accepted: 20702 Total Submissions: 73537 My Submissions
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4. Your algorithm should run in O(n) complexity.
-----------------------------------------------
25:https://oj.leetcode.com/problems/word-ladder-ii/
name:Word Ladder II date:2013-02-10 rate:11.4%
Word Ladder II Total Accepted: 11173 Total Submissions: 98022 My Submissions
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that: Only one letter can be changed at a time Each intermediate word must exist in the dictionary For example, Given: start = "hit" end = "cog" dict = ["hot","dot","dog","lot","log"] Return
[
["hit","hot","dot","dog","cog"],
["hit","hot","lot","log","cog"]
]
Note: All words have the same length. All words contain only lowercase alphabetic characters.
-----------------------------------------------
26:https://oj.leetcode.com/problems/word-ladder/
name:Word Ladder date:2013-02-10 rate:18.3%
Word Ladder Total Accepted: 18572 Total Submissions: 101373 My Submissions
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: Only one letter can be changed at a time Each intermediate word must exist in the dictionary For example, Given: start = "hit" end = "cog" dict = ["hot","dot","dog","lot","log"] As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog", return its length 5. Note: Return 0 if there is no such transformation sequence. All words have the same length. All words contain only lowercase alphabetic characters.
-----------------------------------------------
27:https://oj.leetcode.com/problems/valid-palindrome/
name:Valid Palindrome date:2013-01-12 rate:22.9%
Valid Palindrome Total Accepted: 20559 Total Submissions: 89588 My Submissions
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a palindrome. Note: Have you consider that the string might be empty? This is a good question to ask during an interview. For the purpose of this problem, we define empty string as valid palindrome.
-----------------------------------------------
28:https://oj.leetcode.com/problems/binary-tree-maximum-path-sum/
name:Binary Tree Maximum Path Sum date:2012-11-07 rate:20.0%
Binary Tree Maximum Path Sum Total Accepted: 19694 Total Submissions: 98300 My Submissions
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree,
1
/ \
2 3
Return 6.
-----------------------------------------------
29:https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/
name:Best Time to Buy and Sell Stock III date:2012-11-06 rate:22.3%
Best Time to Buy and Sell Stock III Total Accepted: 15719 Total Submissions: 70473 My Submissions
Say you have an array 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 at most two transactions. Note: You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
-----------------------------------------------
30:https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
name:Best Time to Buy and Sell Stock II date:2012-10-30 rate:36.8%
Best Time to Buy and Sell Stock II Total Accepted: 23845 Total Submissions: 64866 My Submissions
Say you have an array 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 (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
-----------------------------------------------
31:https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock/
name:Best Time to Buy and Sell Stock date:2012-10-30 rate:31.1%
Best Time to Buy and Sell Stock Total Accepted: 23973 Total Submissions: 77095 My Submissions
Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.
-----------------------------------------------
32:https://oj.leetcode.com/problems/triangle/
name:Triangle date:2012-10-29 rate:26.8%
Triangle Total Accepted: 18621 Total Submissions: 69524 My Submissions
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle
[
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11). Note: Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.
-----------------------------------------------
33:https://oj.leetcode.com/problems/pascals-triangle-ii/
name:Pascal's Triangle II date:2012-10-28 rate:30.5%
Pascal's Triangle II Total Accepted: 17564 Total Submissions: 57551 My Submissions
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space?
-----------------------------------------------
34:https://oj.leetcode.com/problems/pascals-triangle/
name:Pascal's Triangle date:2012-10-28 rate:31.6%
Pascal's Triangle Total Accepted: 19670 Total Submissions: 62283 My Submissions
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
-----------------------------------------------
35:https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/
name:Populating Next Right Pointers in Each Node II date:2012-10-28 rate:30.5%
Populating Next Right Pointers in Each Node II Total Accepted: 18311 Total Submissions: 60024 My Submissions
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constant extra space. For example, Given the following binary tree,
1
/ \
2 3
/ \ \
4 5 7
After calling your function, the tree should look like:
1 -> NULL
/ \
2 -> 3 -> NULL
/ \ \
4-> 5 -> 7 -> NULL
-----------------------------------------------
36:https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node/
name:Populating Next Right Pointers in Each Node date:2012-10-28 rate:35.3%
Populating Next Right Pointers in Each Node Total Accepted: 24936 Total Submissions: 70589 My Submissions
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, all next pointers are set to NULL. Note: You may only use constant extra space. You may assume that it is a perfect binary tree (ie, all leaves are at the same level, and every parent has two children). For example, Given the following perfect binary tree,
1
/ \
2 3
/ \ / \
4 5 6 7
After calling your function, the tree should look like:
1 -> NULL
/ \
2 -> 3 -> NULL
/ \ / \
4->5->6->7 -> NULL
-----------------------------------------------
37:https://oj.leetcode.com/problems/distinct-subsequences/
name:Distinct Subsequences date:2012-10-18 rate:24.9%
Distinct Subsequences Total Accepted: 15931 Total Submissions: 64097 My Submissions
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 by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not). Here is an example: S = "rabbbit", T = "rabbit" Return 3.
-----------------------------------------------
38:https://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/
name:Flatten Binary Tree to Linked List date:2012-10-14 rate:28.1%
Flatten Binary Tree to Linked List Total Accepted: 23006 Total Submissions: 81765 My Submissions
Given a binary tree, flatten it to a linked list in-place. For example, Given
1
/ \
2 5
/ \ \
3 4 6
The flattened tree should look like:
1
\
2
\
3
\
4
\
5
\
6
click to show hints. Hints: If you notice carefully in the flattened tree, each node's right child points to the next node of a pre-order traversal.
-----------------------------------------------
39:https://oj.leetcode.com/problems/path-sum-ii/
name:Path Sum II date:2012-10-14 rate:27.0%
Path Sum II Total Accepted: 20581 Total Submissions: 76232 My Submissions
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22,
5
/ \
4 8
/ / \
11 13 4
/ \ / \
7 2 5 1
return
[
[5,4,11,2],
[5,8,4,5]
]
-----------------------------------------------
40:https://oj.leetcode.com/problems/path-sum/
name:Path Sum date:2012-10-13 rate:30.7%
Path Sum Total Accepted: 22768 Total Submissions: 74207 My Submissions
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22,
5
/ \
4 8
/ / \
11 13 4
/ \ \
7 2 1
return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
-----------------------------------------------
41:https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/
name:Minimum Depth of Binary Tree date:2012-10-09 rate:29.6%
Minimum Depth of Binary Tree Total Accepted: 23583 Total Submissions: 79632 My Submissions
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
-----------------------------------------------
42:https://oj.leetcode.com/problems/balanced-binary-tree/
name:Balanced Binary Tree date:2012-10-08 rate:32.8%
Balanced Binary Tree Total Accepted: 25076 Total Submissions: 76517 My Submissions
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
-----------------------------------------------
43:https://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/
name:Convert Sorted List to Binary Search Tree date:2012-10-02 rate:27.4%
Convert Sorted List to Binary Search Tree Total Accepted: 19658 Total Submissions: 71842 My Submissions
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
-----------------------------------------------
44:https://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/
name:Convert Sorted Array to Binary Search Tree date:2012-10-02 rate:32.8%
Convert Sorted Array to Binary Search Tree Total Accepted: 21214 Total Submissions: 64671 My Submissions
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
-----------------------------------------------
45:https://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/
name:Binary Tree Level Order Traversal II date:2012-10-01 rate:31.4%
Binary Tree Level Order Traversal II Total Accepted: 18566 Total Submissions: 59157 My Submissions
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree {3,9,20,#,#,15,7},
3
/ \
9 20
/ \
15 7
return its bottom-up level order traversal as:
[
[15,7],
[9,20],
[3]
]
confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ. OJ's Binary Tree Serialization: The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below. Here's an example:
1
/ \
2 3
/
4
\
5
The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
-----------------------------------------------
46:https://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/
name:Construct Binary Tree from Inorder and Postorder Traversal date:2012-09-30 rate:26.6%
Construct Binary Tree from Inorder and Postorder Traversal Total Accepted: 15266 Total Submissions: 57452 My Submissions
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.
-----------------------------------------------
47:https://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
name:Construct Binary Tree from Preorder and Inorder Traversal date:2012-09-30 rate:26.6%
Construct Binary Tree from Preorder and Inorder Traversal Total Accepted: 15831 Total Submissions: 59527 My Submissions
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.
-----------------------------------------------
48:https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/
name:Maximum Depth of Binary Tree date:2012-09-29 rate:44.0%
Maximum Depth of Binary Tree Total Accepted: 30654 Total Submissions: 69726 My Submissions
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
-----------------------------------------------
49:https://oj.leetcode.com/problems/binary-tree-zigzag-level-order-traversal/
name:Binary Tree Zigzag Level Order Traversal date:2012-09-28 rate:26.7%
Binary Tree Zigzag Level Order Traversal Total Accepted: 16216 Total Submissions: 60825 My Submissions
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 alternate between). For example: Given binary tree {3,9,20,#,#,15,7},
3
/ \
9 20
/ \
15 7
return its zigzag level order traversal as:
[
[3],
[20,9],
[15,7]
]
confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ. OJ's Binary Tree Serialization: The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below. Here's an example:
1
/ \
2 3
/
4
\
5
The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
-----------------------------------------------
50:https://oj.leetcode.com/problems/binary-tree-level-order-traversal/
name:Binary Tree Level Order Traversal date:2012-09-28 rate:30.8%
Binary Tree Level Order Traversal Total Accepted: 22481 Total Submissions: 72874 My Submissions
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,#,#,15,7},
3
/ \
9 20
/ \
15 7
return its level order traversal as:
[
[3],
[9,20],
[15,7]
]
confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ. OJ's Binary Tree Serialization: The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below. Here's an example:
1
/ \
2 3
/
4
\
5
The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
-----------------------------------------------
51:https://oj.leetcode.com/problems/symmetric-tree/
name:Symmetric Tree date:2012-09-23 rate:32.3%
Symmetric Tree Total Accepted: 25223 Total Submissions: 78111 My Submissions
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric:
1
/ \
2 2
/ \ / \
3 4 4 3
But the following is not:
1
/ \
2 2
\ \
3 3
Note: Bonus points if you could solve it both recursively and iteratively. confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ. OJ's Binary Tree Serialization: The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below. Here's an example:
1
/ \
2 3
/
4
\
5
The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
-----------------------------------------------
52:https://oj.leetcode.com/problems/same-tree/
name:Same Tree date:2012-09-03 rate:42.1%
Same Tree Total Accepted: 29126 Total Submissions: 69250 My Submissions
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
-----------------------------------------------
53:https://oj.leetcode.com/problems/recover-binary-search-tree/
name:Recover Binary Search Tree date:2012-09-01 rate:23.7%
Recover Binary Search Tree Total Accepted: 16181 Total Submissions: 68383 My Submissions
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space is pretty straight forward. Could you devise a constant space solution? confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ. OJ's Binary Tree Serialization: The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below. Here's an example:
1
/ \
2 3
/
4
\
5
The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
-----------------------------------------------
54:https://oj.leetcode.com/problems/validate-binary-search-tree/
name:Validate Binary Search Tree date:2012-08-31 rate:25.9%
Validate Binary Search Tree Total Accepted: 21702 Total Submissions: 83809 My Submissions
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees. confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ. OJ's Binary Tree Serialization: The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below. Here's an example:
1
/ \
2 3
/
4
\
5
The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
-----------------------------------------------
55:https://oj.leetcode.com/problems/interleaving-string/
name:Interleaving String date:2012-08-30 rate:19.4%
Interleaving String Total Accepted: 15495 Total Submissions: 80053 My Submissions
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc", return false.
-----------------------------------------------
56:https://oj.leetcode.com/problems/unique-binary-search-trees-ii/
name:Unique Binary Search Trees II date:2012-08-27 rate:27.3%
Unique Binary Search Trees II Total Accepted: 14318 Total Submissions: 52372 My Submissions
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique BST's shown below.
1 3 3 2 1
\ / / / \ \
3 2 1 1 3 2
/ / \ \
2 1 2 3
confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ. OJ's Binary Tree Serialization: The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below. Here's an example:
1
/ \
2 3
/
4
\
5
The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
-----------------------------------------------
57:https://oj.leetcode.com/problems/unique-binary-search-trees/
name:Unique Binary Search Trees date:2012-08-27 rate:36.6%
Unique Binary Search Trees Total Accepted: 24815 Total Submissions: 67754 My Submissions
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's.
1 3 3 2 1
\ / / / \ \
3 2 1 1 3 2
/ / \ \
2 1 2 3
-----------------------------------------------
58:https://oj.leetcode.com/problems/binary-tree-inorder-traversal/
name:Binary Tree Inorder Traversal date:2012-08-27 rate:35.6%
Binary Tree Inorder Traversal Total Accepted: 31765 Total Submissions: 89122 My Submissions
Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3},
1
\
2
/
3
return [1,3,2]. Note: Recursive solution is trivial, could you do it iteratively? confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ. OJ's Binary Tree Serialization: The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below. Here's an example:
1
/ \
2 3
/
4
\
5
The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
-----------------------------------------------
59:https://oj.leetcode.com/problems/restore-ip-addresses/
name:Restore IP Addresses date:2012-08-07 rate:20.5%
Restore IP Addresses Total Accepted: 14929 Total Submissions: 72764 My Submissions
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", "255.255.111.35"]. (Order does not matter)
-----------------------------------------------
60:https://oj.leetcode.com/problems/reverse-linked-list-ii/
name:Reverse Linked List II date:2012-06-27 rate:26.1%
Reverse Linked List II Total Accepted: 18981 Total Submissions: 72811 My Submissions
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. Note: Given m, n satisfy the following condition: 1 ≤ m ≤ n ≤ length of list.
-----------------------------------------------
61:https://oj.leetcode.com/problems/subsets-ii/
name:Subsets II date:2012-06-25 rate:27.1%
Subsets II Total Accepted: 17592 Total Submissions: 65028 My Submissions
Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If S = [1,2,2], a solution is:
[
[2],
[1],
[1,2,2],
[2,2],
[1,2],
[]
]
-----------------------------------------------
62:https://oj.leetcode.com/problems/decode-ways/
name:Decode Ways date:2012-06-25 rate:16.1%
Decode Ways Total Accepted: 16564 Total Submissions: 102756 My Submissions
A message containing letters from A-Z is being encoded to numbers using the following mapping:
'A' -> 1
'B' -> 2
...
'Z' -> 26
Given an encoded message containing digits, determine the total number of ways to decode it. For example, Given encoded message "12", it could be decoded as "AB" (1 2) or "L" (12). The number of ways decoding "12" is 2.
-----------------------------------------------
63:https://oj.leetcode.com/problems/gray-code/
name:Gray Code date:2012-05-20 rate:32.1%
Gray Code Total Accepted: 16781 Total Submissions: 52314 My Submissions
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. For example, given n = 2, return [0,1,3,2]. Its gray code sequence is:
00 - 0
01 - 1
11 - 3
10 - 2
Note: For a given n, a gray code sequence is not uniquely defined. For example, [0,2,3,1] is also a valid gray code sequence according to the above definition. For now, the judge is able to judge based on one instance of gray code sequence. Sorry about that.
-----------------------------------------------
64:https://oj.leetcode.com/problems/merge-sorted-array/
name:Merge Sorted Array date:2012-05-20 rate:32.2%
Merge Sorted Array Total Accepted: 23723 Total Submissions: 73653 My Submissions
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.
-----------------------------------------------
65:https://oj.leetcode.com/problems/scramble-string/
name:Scramble String date:2012-04-30 rate:22.7%
Scramble String Total Accepted: 13443 Total Submissions: 59201 My Submissions
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great":
great
/ \
gr eat
/ \ / \
g r e at
/ \
a t
To scramble the string, we may choose any non-leaf node and swap its two children. For example, if we choose the node "gr" and swap its two children, it produces a scrambled string "rgeat".
rgeat
/ \
rg eat
/ \ / \
r g e at
/ \
a t
We say that "rgeat" is a scrambled string of "great". Similarly, if we continue to swap the children of nodes "eat" and "at", it produces a scrambled string "rgtae".
rgtae
/ \
rg tae
/ \ / \
r g ta e
/ \
t a
We say that "rgtae" is a scrambled string of "great". Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.
-----------------------------------------------
66:https://oj.leetcode.com/problems/partition-list/
name:Partition List date:2012-04-30 rate:26.9%
Partition List Total Accepted: 18147 Total Submissions: 67382 My Submissions
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 the nodes in each of the two partitions. For example, Given 1->4->3->2->5->2 and x = 3, return 1->2->2->4->3->5.
-----------------------------------------------
67:https://oj.leetcode.com/problems/maximal-rectangle/
name:Maximal Rectangle date:2012-04-23 rate:21.6%
Maximal Rectangle Total Accepted: 11792 Total Submissions: 54589 My Submissions
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.
-----------------------------------------------
68:https://oj.leetcode.com/problems/largest-rectangle-in-histogram/
name:Largest Rectangle in Histogram date:2012-04-22 rate:21.4%
Largest Rectangle in Histogram Total Accepted: 16727 Total Submissions: 78113 My Submissions
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3]. The largest rectangle is shown in the shaded area, which has area = 10 unit. For example, Given height = [2,1,5,6,2,3], return 10.
-----------------------------------------------
69:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/
name:Remove Duplicates from Sorted List II date:2012-04-22 rate:24.9%
Remove Duplicates from Sorted List II Total Accepted: 19945 Total Submissions: 80213 My Submissions
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->3->3->4->4->5, return 1->2->5. Given 1->1->1->2->3, return 2->3.
-----------------------------------------------
70:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/
name:Remove Duplicates from Sorted List date:2012-04-22 rate:35.2%
Remove Duplicates from Sorted List Total Accepted: 27171 Total Submissions: 77185 My Submissions
Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.
-----------------------------------------------
71:https://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/
name:Search in Rotated Sorted Array II date:2012-04-19 rate:30.8%
Search in Rotated Sorted Array II Total Accepted: 16997 Total Submissions: 55210 My Submissions
Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a function to determine if a given target is in the array.
-----------------------------------------------
72:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/
name:Remove Duplicates from Sorted Array II date:2012-04-19 rate:30.7%
Remove Duplicates from Sorted Array II Total Accepted: 19884 Total Submissions: 64751 My Submissions
Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For example, Given sorted array A = [1,1,1,2,2,3], Your function should return length = 5, and A is now [1,1,2,2,3].
-----------------------------------------------
73:https://oj.leetcode.com/problems/word-search/
name:Word Search date:2012-04-18 rate:19.9%
Word Search Total Accepted: 15460 Total Submissions: 77713 My Submissions
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once. For example, Given board =
[
["ABCE"],
["SFCS"],
["ADEE"]
]
word = "ABCCED", -> returns true, word = "SEE", -> returns true, word = "ABCB", -> returns false.
-----------------------------------------------
74:https://oj.leetcode.com/problems/subsets/
name:Subsets date:2012-04-18 rate:27.8%
Subsets Total Accepted: 22670 Total Submissions: 81484 My Submissions
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If S = [1,2,3], a solution is:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
]
-----------------------------------------------
75:https://oj.leetcode.com/problems/combinations/
name:Combinations date:2012-04-18 rate:30.3%
Combinations Total Accepted: 20553 Total Submissions: 67789 My Submissions
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is:
[
[2,4],
[3,4],
[2,3],
[1,2],
[1,3],
[1,4],
]
-----------------------------------------------
76:https://oj.leetcode.com/problems/minimum-window-substring/
name:Minimum Window Substring date:2012-04-15 rate:18.1%
Minimum Window Substring Total Accepted: 14236 Total Submissions: 78777 My Submissions
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example, S = "ADOBECODEBANC" T = "ABC" Minimum window is "BANC". Note: If there is no such window in S that covers all characters in T, return the emtpy string "". If there are multiple such windows, you are guaranteed that there will always be only one unique minimum window in S.
-----------------------------------------------
77:https://oj.leetcode.com/problems/sort-colors/
name:Sort Colors date:2012-04-08 rate:32.1%
Sort Colors Total Accepted: 23996 Total Submissions: 74708 My Submissions
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively. Note: You are not suppose to use the library's sort function for this problem. click to show follow up. Follow up: A rather straight forward solution is a two-pass algorithm using counting sort. First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's. Could you come up with an one-pass algorithm using only constant space?
-----------------------------------------------
78:https://oj.leetcode.com/problems/search-a-2d-matrix/
name:Search a 2D Matrix date:2012-04-06 rate:31.2%
Search a 2D Matrix Total Accepted: 20154 Total Submissions: 64594 My Submissions
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous row. For example, Consider the following matrix:
[
[1, 3, 5, 7],
[10, 11, 16, 20],
[23, 30, 34, 50]
]
Given target = 3, return true.
-----------------------------------------------
79:https://oj.leetcode.com/problems/set-matrix-zeroes/
name:Set Matrix Zeroes date:2012-04-05 rate:30.9%
Set Matrix Zeroes Total Accepted: 17654 Total Submissions: 57138 My Submissions
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space? A straight forward solution using O(mn) space is probably a bad idea. A simple improvement uses O(m + n) space, but still not the best solution. Could you devise a constant space solution?
-----------------------------------------------
80:https://oj.leetcode.com/problems/edit-distance/
name:Edit Distance date:2012-04-04 rate:25.3%
Edit Distance Total Accepted: 15420 Total Submissions: 60856 My Submissions
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word: a) Insert a character b) Delete a character c) Replace a character
-----------------------------------------------
81:https://oj.leetcode.com/problems/simplify-path/
name:Simplify Path date:2012-04-03 rate:19.9%
Simplify Path Total Accepted: 12487 Total Submissions: 62601 My Submissions
Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" click to show corner cases. Corner Cases: Did you consider the case where path = "/../"? In this case, you should return "/". Another corner case is the path might contain multiple slashes '/' together, such as "/home//foo/". In this case, you should ignore redundant slashes and return "/home/foo".
-----------------------------------------------
82:https://oj.leetcode.com/problems/climbing-stairs/
name:Climbing Stairs date:2012-04-03 rate:34.1%
Climbing Stairs Total Accepted: 24096 Total Submissions: 70752 My Submissions
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
-----------------------------------------------
83:https://oj.leetcode.com/problems/sqrtx/
name:Sqrt(x) date:2012-04-03 rate:22.3%
Sqrt(x) Total Accepted: 23641 Total Submissions: 105943 My Submissions
Implement int sqrt(int x). Compute and return the square root of x.
-----------------------------------------------
84:https://oj.leetcode.com/problems/text-justification/
name:Text Justification date:2012-04-03 rate:14.0%
Text Justification Total Accepted: 9018 Total Submissions: 64188 My Submissions
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified. You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly L characters. Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right. For the last line of text, it should be left justified and no extra space is inserted between words. For example, words: ["This", "is", "an", "example", "of", "text", "justification."] L: 16. Return the formatted lines as:
[
"This is an",
"example of text",
"justification. "
]
Note: Each word is guaranteed not to exceed L in length. click to show corner cases. Corner Cases: A line other than the last line might contain only one word. What should you do in this case? In this case, that line should be left-justified.
-----------------------------------------------
85:https://oj.leetcode.com/problems/plus-one/
name:Plus One date:2012-04-02 rate:31.7%
Plus One Total Accepted: 19844 Total Submissions: 62688 My Submissions
Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list.
-----------------------------------------------
86:https://oj.leetcode.com/problems/valid-number/
name:Valid Number date:2012-04-02 rate:11.1%
Valid Number Total Accepted: 11605 Total Submissions: 104749 My Submissions
Validate if a given string is numeric. Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
-----------------------------------------------
87:https://oj.leetcode.com/problems/add-binary/
name:Add Binary date:2012-04-02 rate:26.0%
Add Binary Total Accepted: 17525 Total Submissions: 67379 My Submissions
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100".
-----------------------------------------------
88:https://oj.leetcode.com/problems/merge-two-sorted-lists/
name:Merge Two Sorted Lists date:2012-03-30 rate:33.3%
Merge Two Sorted Lists Total Accepted: 25214 Total Submissions: 75669 My Submissions
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
-----------------------------------------------
89:https://oj.leetcode.com/problems/minimum-path-sum/
name:Minimum Path Sum date:2012-03-28 rate:31.3%
Minimum Path Sum Total Accepted: 17777 Total Submissions: 56864 My Submissions
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time.
-----------------------------------------------
90:https://oj.leetcode.com/problems/unique-paths-ii/
name:Unique Paths II date:2012-03-28 rate:27.9%
Unique Paths II Total Accepted: 15377 Total Submissions: 55184 My Submissions
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. For example, There is one obstacle in the middle of a 3x3 grid as illustrated below.
[
[0,0,0],
[0,1,0],
[0,0,0]
]
The total number of unique paths is 2. Note: m and n will be at most 100.
-----------------------------------------------
91:https://oj.leetcode.com/problems/unique-paths/
name:Unique Paths date:2012-03-28 rate:31.6%
Unique Paths Total Accepted: 20193 Total Submissions: 63918 My Submissions
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below). How many possible unique paths are there? Above is a 3 x 7 grid. How many possible unique paths are there? Note: m and n will be at most 100.
-----------------------------------------------
92:https://oj.leetcode.com/problems/rotate-list/
name:Rotate List date:2012-03-27 rate:22.1%
Rotate List Total Accepted: 16912 Total Submissions: 76478 My Submissions
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.
-----------------------------------------------
93:https://oj.leetcode.com/problems/permutation-sequence/
name:Permutation Sequence date:2012-03-27 rate:22.2%
Permutation Sequence Total Accepted: 13622 Total Submissions: 61331 My Submissions
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): "123" "132" "213" "231" "312" "321" Given n and k, return the kth permutation sequence. Note: Given n will be between 1 and 9 inclusive.
-----------------------------------------------
94:https://oj.leetcode.com/problems/spiral-matrix-ii/
name:Spiral Matrix II date:2012-03-27 rate:30.8%
Spiral Matrix II Total Accepted: 14109 Total Submissions: 45845 My Submissions
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Given n = 3, You should return the following matrix:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
]
-----------------------------------------------
95:https://oj.leetcode.com/problems/length-of-last-word/
name:Length of Last Word date:2012-03-27 rate:29.5%
Length of Last Word Total Accepted: 18858 Total Submissions: 64014 My Submissions
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word is defined as a character sequence consists of non-space characters only. For example, Given s = "Hello World", return 5.
-----------------------------------------------
96:https://oj.leetcode.com/problems/insert-interval/
name:Insert Interval date:2012-03-27 rate:20.7%
Insert Interval Total Accepted: 15546 Total Submissions: 75238 My Submissions
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1: Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9]. Example 2: Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] in as [1,2],[3,10],[12,16]. This is because the new interval [4,9] overlaps with [3,5],[6,7],[8,10].
-----------------------------------------------
97:https://oj.leetcode.com/problems/merge-intervals/
name:Merge Intervals date:2012-03-26 rate:20.9%
Merge Intervals Total Accepted: 16100 Total Submissions: 77162 My Submissions
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].
-----------------------------------------------
98:https://oj.leetcode.com/problems/jump-game/
name:Jump Game date:2012-03-24 rate:27.2%
Jump Game Total Accepted: 20013 Total Submissions: 73507 My Submissions
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. Determine if you are able to reach the last index. For example: A = [2,3,1,1,4], return true. A = [3,2,1,0,4], return false.
-----------------------------------------------
99:https://oj.leetcode.com/problems/spiral-matrix/
name:Spiral Matrix date:2012-03-24 rate:20.6%
Spiral Matrix Total Accepted: 14205 Total Submissions: 68858 My Submissions
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix:
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
You should return [1,2,3,6,9,8,7,4,5].
-----------------------------------------------
100:https://oj.leetcode.com/problems/maximum-subarray/
name:Maximum Subarray date:2012-03-21 rate:33.8%
Maximum Subarray Total Accepted: 25920 Total Submissions: 76642 My Submissions
Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has the largest sum = 6. click to show more practice. More practice: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.
-----------------------------------------------
101:https://oj.leetcode.com/problems/n-queens-ii/
name:N-Queens II date:2012-03-20 rate:33.5%
N-Queens II Total Accepted: 13501 Total Submissions: 40357 My Submissions
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions.
-----------------------------------------------
102:https://oj.leetcode.com/problems/n-queens/
name:N-Queens date:2012-03-19 rate:25.9%
N-Queens Total Accepted: 15032 Total Submissions: 57952 My Submissions
The n-queens puzzle is the problem of placing n queens on an n×n ches