- 博客(55)
- 资源 (7)
- 收藏
- 关注
原创 Increasing Subsequences
Increasing Subsequences Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be
2017-04-27 17:00:20 198
原创 Find Mode in Binary Search Tree
Find Mode in Binary Search Tree Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is defined as fol
2017-04-27 16:01:07 176
原创 Partition Equal Subset Sum
Partition Equal Subset Sum Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.
2017-04-27 10:36:04 164
原创 Increasing Triplet Subsequence
Increasing Triplet Subsequence Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array. Formally the function should: Return true if there
2017-04-26 16:39:30 174
原创 Combinations
Combinations 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],
2017-04-26 15:23:40 159
原创 Subsets
Subsets Given a set of distinct integers, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example, If nums = [1,2,3], a solution is: [
2017-04-26 11:35:28 193
原创 Spiral Matrix II
Spiral Matrix II 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,
2017-04-25 23:02:29 150
原创 Insert Delete GetRandom O(1)
Insert Delete GetRandom O(1) Design a data structure that supports all following operations in average O(1) time. insert(val): Inserts an item val to the set if not already present.remove(
2017-04-25 22:27:56 131
原创 Binary Tree Postorder Traversal
Binary Tree Postorder Traversal Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 r
2017-04-25 21:54:52 187
原创 Binary Tree Right Side View
Binary Tree Right Side View Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example: Given
2017-04-25 21:48:47 161
原创 Best Time to Buy and Sell Stock with Cooldown
Best Time to Buy and Sell Stock with Cooldown 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
2017-04-25 21:26:49 412
原创 Evaluate Division
Evaluate Division Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return t
2017-04-25 15:03:43 253
原创 Binary Search Tree Iterator
Binary Search Tree Iterator Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest
2017-04-25 11:22:47 137
原创 Flatten Nested List Iterator
Flatten Nested List Iterator Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list -- whose elements may also be integers or other
2017-04-25 10:41:59 221
原创 Lexicographical Numbers
Lexicographical Numbers Given an integer n, return 1 - n in lexicographical order. For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9]. Please optimize your algorithm to use less
2017-04-25 10:08:03 169
原创 Non-overlapping Intervals
Non-overlapping Intervals Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. Note: You may assum
2017-04-24 21:38:39 302
原创 Elimination Game
Elimination Game There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and every other number afterward until you reach the end of the list. Re
2017-04-24 17:31:17 187
原创 Brick Wall
Brick Wall There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line fro
2017-04-24 16:34:16 377
原创 N-Queens II
N-Queens II Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. 解析:递归解法,按行递归,考虑当前行应该放的位置,确定一个位置对下面所有行进行递归求解,当当前行
2017-04-24 11:16:31 235
原创 N-Queens
N-Queens The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n
2017-04-24 11:14:24 207
原创 Binary Tree Tilt
Binary Tree Tilt Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the s
2017-04-23 21:49:09 477
原创 Search Insert Position
Search Insert Position Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assu
2017-04-23 21:44:48 362
原创 Random Pick Index
Random Pick Index Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.
2017-04-23 15:44:32 150
原创 Permutations
Permutations Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1],
2017-04-23 15:02:19 205
原创 Longest Palindromic Subsequence
Longest Palindromic Subsequence Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000. Example 1: Input: "bbbab" Out
2017-04-23 13:33:31 216
原创 Combination Sum
组合数之和,一共四题,前三题需要输出数组,第四题只需输出个数 1. Combination Sum Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate num
2017-04-22 21:26:35 224
原创 Minimum Number of Arrows to Burst Balloons
Minimum Number of Arrows to Burst Balloons There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horiz
2017-04-21 15:24:36 225
原创 Serialize and Deserialize BST
Serialize and Deserialize BST 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 a
2017-04-21 11:22:30 290
原创 Unique Binary Search Trees II
Unique Binary Search Trees II Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return
2017-04-20 10:26:49 162
原创 Different Ways to Add Parentheses
Different Ways to Add Parentheses Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid o
2017-04-19 22:41:12 175
原创 Predict the Winner
Predict the Winner Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on.
2017-04-19 14:55:06 215
原创 Diameter of Binary Tree
Diameter of Binary Tree Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longestpath between any two nodes in
2017-04-19 13:25:16 167
原创 Student Attendance Record I
Student Attendance Record I You are given a string representing an attendance record for a student. The record only contains the following three characters: 'A' : Absent.'L' : Late.'P' :
2017-04-19 10:55:00 749
原创 Reverse String II
Reverse String II Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters le
2017-04-19 10:40:34 222
原创 Number of Boomerangs
Number of Boomerangs Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between iand j equals the distance betwe
2017-04-19 10:25:45 203
原创 Minimum Time Difference
Minimum Time Difference Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minutes difference between any two time points in the list. Example 1: Input:
2017-04-18 19:39:50 268
原创 Base 7
Base 7 Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202" Example 2: Input: -7 Output: "-10" 解析:简单题,求一个数的七进制 代码: class Solution { p
2017-04-18 15:28:57 242
原创 Add Two Numbers II
Add Two Numbers II You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the
2017-04-18 15:11:08 185
原创 Total Hamming Distance
Total Hamming Distance The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Now your job is to find the total Hamming distance
2017-04-18 10:08:23 176
原创 Diagonal Traverse
Diagonal Traverse Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image. Example: Input: [ [ 1, 2, 3 ], [
2017-04-17 16:45:12 322
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人