[LeetCode] Edit Distance
Edit DistanceGiven 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 foll...
[LeetCode] Missing Number
Missing NumberGiven 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] ...
[LeetCode] Text Justification
Text JustificationGiven 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...
[LeetCode] Merge Intervals
Merge IntervalsGiven 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].解题思路:数组区域合并。首先将原数组按照左边界排序,然后扫描数组。每次比较...
[LeetCode] Insert Interval
Insert IntervalGiven 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 th...
[LeetCode] N-Queens II
N-Queens IIFollow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.解题思路:这道题与http://blog.csdn.net/kangrydotnet/article/details/4785746...
[LeetCode] N-Queens
N-QueensThe 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 solu...
[LeetCode] Ugly Number II
Ugly Number IIWrite 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 i...
网站下的robots
面试某软,被面试官问道:你做爬虫,知不知道很多网站下都有个robots文件? 答曰:不知。 于是面试官给我演示了一遍~ 遂卒。首战惨败。 下来查了维基百科,基本了解ro...
[LeetCode] Group Anagrams
Group AnagramsGiven an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], R...
[LeetCode] Ugly Number
Ugly NumberWrite 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...
[LeetCode] Binary Tree Paths
Binary Tree PathsGiven a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \ 2 3 &nbs...
[LeetCode] Different Ways to Add Parentheses
Different Ways to Add ParenthesesGiven 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...
[LeetCode] Sort List
Sort ListSort a linked list in O(n log n) time using constant space complexity.解题思路:题意为以常量存储空间和O(nlogn)时间复杂度来排序链表。可以用合并排序法,并用双指针法来找到中间节点。产生一个头结点方便编码。/** * Definition fo...
[LeetCode] Add Digits
Add DigitsGiven 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...
[LeetCode] Single Number III
Single Number IIIGiven 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 ex...
[LeetCode] Clone Graph
Clone GraphClone 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 ...
[LeetCode] Surrounded Regions
Surrounded RegionsGiven a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into...
[LeetCode] Gas Station
Gas StationThere 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]&...
[LeetCode] Palindrome Partitioning
Palindrome PartitioningGiven 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&...