- 博客(254)
- 收藏
- 关注
原创 Git for Beginner
How to upload your code to git server?After installing git, execute these in command line:git config --global user.name "Your Name"git config --global user.email "email@example.com*******...
2016-05-17 16:15:21
232
原创 Word Break II
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, givens = "...
2016-03-09 03:15:18
207
原创 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.E...
2016-03-08 02:11:59
237
原创 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].题目中给定了一个interval集合,要求我们将集合中的interval合并,合并之后的interv...
2016-03-07 05:25:18
199
原创 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Merge k个有序链表,之前做过一道题目是merge两个有序的链表,这里我们用分治的思想,用归并排序解决。先将k个链表递归的分为两部分,直到剩下两个链表,然后将两个链表合并起来。因为有k个lis...
2016-03-07 04:03:59
131
原创 Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.计算两个大数的乘法,如果直接计算,就会溢出。假设两个数的长度分别为m, n...
2016-03-06 07:27:43
119
原创 N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.[img]http://www.leetcode.com/wp-content/uploads/2012/03/8-queens.png[/i...
2016-03-06 03:06:13
102
原创 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.[img]http://www.leetcode.com/wp-content/uploads/2012/03/8-queens.png[/img]Give...
2016-03-06 02:47:03
122
原创 First Missing Positive
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant...
2016-03-05 03:09:50
98
原创 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 ]...
2016-03-04 03:39:39
98
原创 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-03-04 02:54:10
98
原创 Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri...
2016-03-03 03:10:23
102
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 exists i, j, k such that arr[i] < arr[...
2016-03-02 02:48:41
96
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-03-02 01:56:43
129
原创 LRU Cache
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 ...
2016-02-29 10:37:04
95
原创 Super Ugly Number
Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14,...
2016-02-29 07:07:06
92
原创 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...
2016-02-29 05:56:26
142
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 money ...
2016-02-29 04:39:09
115
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 mini...
2016-02-29 04:11:10
99
原创 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 off ...
2016-02-28 12:12:56
103
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...
2016-02-28 05:03:02
93
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?判断一个整数是否为3的幂。如果一个整数是3的幂,那么就可以表示为3 ^ x = n [color=vio...
2016-02-28 04:58:57
68
原创 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], ther...
2016-02-28 04:22:24
109
原创 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 hint tha...
2016-02-28 03:30:18
342
原创 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...
2016-02-27 05:11:30
90
原创 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-02-27 03:37:55
189
原创 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 in pattern and a non-empty word in str.Ex...
2016-02-27 03:29:56
91
Game of Life
According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m by...
2016-02-27 03:15:50
67
Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi...
2016-02-27 02:26:25
79
原创 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 be retu...
2016-02-26 05:08:17
86
原创 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 your ...
2016-02-26 04:38:42
108
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 the...
2016-02-26 03:07:46
94
原创 H-Index II
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?这道题目是H-Index的follow up。题目的意思让我们在O(log n)的时间复杂度下解决。我们用二分法,这道题目比较trick, 代码如下:[cod...
2016-02-26 02:56:52
135
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: "A ...
2016-02-26 02:25:10
314
原创 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.通过位运算,将数组里面的元素与对应的下标进行异或运算,得到...
2016-02-25 03:46:30
98
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 10...
2016-02-25 03:36:15
74
原创 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 since ...
2016-02-25 02:45:56
91
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 nu...
2016-02-25 02:20:31
73
原创 Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]给定一个二叉树...
2016-02-25 01:40:47
96
原创 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 1...
2016-02-24 10:03:55
80
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人