- 博客(280)
- 收藏
- 关注
原创 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 outsi
2016-02-08 14:08:06 469
原创 Leetcode: 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 elements in the array.
2016-02-08 13:09:22 510
原创 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-02-07 17:33:07 571
原创 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
2016-01-17 23:47:14 465
原创 Leetcode: Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the follow
2016-01-17 23:35:26 363
原创 Leetcode: Integer to English Words
Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example,123 -> "One Hundred Twenty Three"12345 -> "Twelve Thousand Thre
2016-01-11 23:35:28 309
原创 Leetcode: Game of Life
According to the Wikipedia's article: "The Game of Life, also known simply asLife, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with
2016-01-11 22:40:26 402
原创 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 ord
2016-01-10 23:55:53 406
原创 Leetcode: Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because12 = 4 + 4 + 4; given n =
2016-01-10 14:29:10 339
原创 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
2016-01-10 00:20:09 334
原创 Leetcode: Minimum Height Trees
For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called
2016-01-09 23:46:22 514
原创 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? 没啥意思的题,循环解法。class Solution {public: bool isPowerOf
2016-01-08 23:13:15 394
原创 Leetcode: Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case lett
2016-01-07 23:55:38 391
原创 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
2016-01-03 15:59:45 505
原创 Leetcode: 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 dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one
2016-01-03 14:21:30 449
原创 Leetcode: Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning
2016-01-03 00:28:30 346
原创 Leetcode: Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of mo
2015-12-28 00:44:21 404
原创 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 t
2015-12-27 17:09:13 347
原创 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 t
2015-12-20 00:53:42 359
原创 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], th
2015-12-19 17:41:06 300
原创 Leetcode: 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 operators are+, - and *.Example
2015-12-19 15:59:11 375
原创 Leetcode: Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hi
2015-12-19 14:58:33 309
原创 Leetcode: Range Sum Query - Mutable
Given an integer array nums, find the sum of the elements between indicesi and j (i ≤ j), inclusive.The update(i, val) function modifies nums by updating the element at indexi to val.Examp
2015-12-13 21:58:26 534
原创 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) -> -1sum
2015-12-13 10:35:37 304
原创 Leetcode: Peeking Iterator
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will b
2015-12-09 23:58:43 380
原创 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
2015-12-09 23:20:50 339
原创 Leetcode: Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter inpattern and a non-empty word in str.E
2015-12-09 00:17:12 337
原创 Leetcode: Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you
2015-09-19 23:59:24 354
原创 Leetcode: First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on
2015-09-09 23:19:51 284
原创 Leetcode: H-Index II
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?二分查找,时间复杂度O(logn)。class Solution {public: int hIndex(vector& citatio
2015-09-05 16:22:12 388
原创 Leetcode: H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h-index on Wikipedia:
2015-09-05 15:47:47 419
原创 Leetcode: Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2. Note:Your algorithm should
2015-08-30 15:46:39 273
原创 Leetcode: Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements
2015-08-23 17:37:23 390
原创 Leetcode: Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially
2015-08-23 15:18:35 288
原创 Leetcode: Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example: Given n
2015-08-20 23:46:43 335
原创 Leetcode: Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example,1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first
2015-08-20 23:18:13 504
原创 Leetcode: Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example,6, 8 are ugly while 14 is not ugly sin
2015-08-20 22:56:37 324
原创 Leetcode: Course Schedule II
There are a total of n courses you have to take, labeled from 0 ton - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as
2015-08-18 23:45:54 349
原创 Leetcode: Course Schedule
There are a total of n courses you have to take, labeled from 0 ton - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as
2015-08-18 00:20:15 323
原创 Leetcode: Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only
2015-08-16 22:33:00 328
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人