- 博客(208)
- 收藏
- 关注
原创 [Leetcode]Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excludin
2016-09-05 13:52:37
432
原创 [Leetcode]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
2016-08-22 15:25:56
490
原创 [Leetcode]Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be construc
2016-08-22 15:17:32
476
原创 [Leetcode]Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true.Given num = 5, return false.Follow up: Could you solve it without loop
2016-06-24 15:31:12
301
原创 [Leetcode]Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".Subscrib
2016-06-23 15:04:16
227
原创 [Leetcode]Power of Three
Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?Credits:Special thanks to @dietpepsi for adding this pr
2016-06-23 11:14:00
270
原创 [Leetcode]Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return[2, 2].Note:Each element in the result should appear as many ti
2016-06-21 12:23:53
357
原创 [Leetcode]Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return[2].Note:Each element in the result must be unique.The result c
2016-06-20 18:37:36
258
原创 [Leetcode]Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the
2016-06-20 18:27:20
265
原创 [Leetcode]Verify Preorder Serialization of a Binary Tree
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as#.
2016-03-15 18:51:00
332
原创 [Leetcode]Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside o
2016-03-14 14:49:11
350
原创 [Leetcode]Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku puzzle.
2016-03-10 19:42:23
302
原创 [Leetcode]Jump Game II
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.Your goal is
2016-03-09 22:40:57
338
原创 [Leetcode]Scramble String
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
2016-02-19 11:14:09
306
原创 [Leetcode]Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], theref
2016-01-30 11:47:16
289
原创 [Leetcode]Insert Interval
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.Examp
2016-01-29 16:14:55
342
原创 [Leetcode]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]./** * Definition for an interval. * struct Inter
2016-01-29 15:31:12
328
原创 [Leetcode]Remove Duplicate Letters
Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order a
2016-01-29 12:15:19
452
原创 [Leetcode]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 elements to the right of nums[i].Example:G
2016-01-20 18:08:32
1056
原创 [Leetcode]Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convertword1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:
2016-01-18 14:41:11
310
原创 [Leetcode]Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in p
2016-01-16 20:55:51
361
原创 [Leetcode]Remove Invalid Parentheses
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses ( and).
2016-01-14 20:14:43
343
原创 [Leetcode]Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences ofT in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none
2016-01-08 10:43:05
309
原创 [Leetcode]Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]
2016-01-05 10:19:10
310
原创 [Leetcode]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
2015-12-28 20:17:08
345
原创 [Leetcode]Longest Consecutive Sequence
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,
2015-12-17 20:06:59
450
原创 [Leetcode]N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.class Solution {public: /*algorithm: DFS */ vectorgetNex
2015-12-15 17:22:33
293
原创 [Leetcode]N-Queens
The n-queens puzzle is the problem of placing n queens on ann×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Ea
2015-12-15 16:55:08
266
原创 [cc150]Chapter 3 | Stacks and Queues
Describe how you could use a single array to implement three stacks.1)solution 1 divide the array to 3 part, so each part can be one stack, but for each stack is limited to n/3 size [stk1][stk
2015-12-04 14:42:51
315
原创 [Leetcode]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 / 3return [3,2,1].Note: Recursive solution is tri
2015-12-03 18:10:20
247
原创 [Leetcode]Additive Number
Additive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the s
2015-12-02 23:22:40
592
原创 [Leetcode]Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 andn (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, f
2015-12-01 15:37:38
264
原创 [Leetcode]Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence frombeginWord to endWord, such that:Only one letter can be changed at a
2015-11-25 17:05:54
279
原创 [Leetcode]Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indicesi and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRang
2015-11-23 15:11:08
232
原创 [Leetcode]Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution {public: /*algorithm binary search */ int bSearch(lon
2015-11-19 15:11:26
260
原创 [Leetcode]Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place in O(1
2015-11-18 00:08:17
268
原创 [Leetcode]Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"class Solution {public: /*algorithm for simplici
2015-11-14 22:06:12
269
原创 [Leetcode]Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For
2015-11-14 16:57:23
245
原创 [Leetcode]Range Sum Query 2D - Immutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1,col1) and lower right corner (row2, col2).The above rectangle (with the red bor
2015-11-14 16:11:38
262
原创 [Leetcode]Spiral Matrix
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
2015-11-13 22:29:44
192
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人