
leetcode
文章平均质量分 68
shuimuyq
这个作者很懒,什么都没留下…
展开
-
070 - Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?int climbStairs(int n) {原创 2015-12-30 16:45:16 · 413 阅读 · 0 评论 -
040 - Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.Each number in C may only be used once in the combinatio原创 2015-11-19 17:12:14 · 295 阅读 · 0 评论 -
052 - N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.static int Q; static int retcur;int locok(char **queen, int cu原创 2015-11-26 18:24:51 · 322 阅读 · 0 评论 -
049 - Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note:For t原创 2015-11-25 17:32:37 · 423 阅读 · 0 评论 -
046 - Permutations
Given a collection of 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],[3,1,2], and [3,2,1].static int原创 2015-11-25 17:30:19 · 293 阅读 · 0 评论 -
044 - Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover原创 2015-11-25 17:28:18 · 211 阅读 · 0 评论 -
050 - Pow(x, n)
Implement pow(x, n).double myPow(double x, int n) { int flag = 0; if (n == 0) return fabs(x) < 0.000001? 0 : 1; if (n == INT_MIN) return fabs(x) >= 1.000000 && fabs(原创 2015-11-25 17:33:37 · 435 阅读 · 0 评论 -
047 - Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].原创 2015-11-25 17:30:52 · 262 阅读 · 0 评论 -
045 - 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原创 2015-11-25 17:29:02 · 254 阅读 · 0 评论 -
041 - 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 spa原创 2015-11-25 17:24:08 · 250 阅读 · 0 评论 -
039 - Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numbe原创 2015-11-19 17:07:41 · 287 阅读 · 0 评论 -
038 - Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "one 2原创 2015-11-19 17:05:32 · 228 阅读 · 0 评论 -
037 - 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.原创 2015-11-19 17:02:38 · 301 阅读 · 0 评论 -
036 - Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character'.'.A partially filled s原创 2015-11-19 17:00:39 · 303 阅读 · 0 评论 -
048 - Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?void rotate(int** matrix, int matrixRowSize, int原创 2015-11-25 17:31:48 · 265 阅读 · 0 评论 -
043 - 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.static void turnaround(char *str)原创 2015-11-25 17:26:44 · 364 阅读 · 0 评论 -
051 - 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-11-26 18:23:44 · 388 阅读 · 0 评论 -
053 - Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] has原创 2015-11-26 18:26:11 · 354 阅读 · 0 评论 -
054 - 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-26 18:27:06 · 273 阅读 · 0 评论 -
069 - Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.int mySqrt(int x){ int left = 1; int right = x >= 50000 ? 50000 : x; int mid; while (left <= right) { mid = (left + rig原创 2015-12-30 16:44:07 · 323 阅读 · 0 评论 -
068 - Text Justification
Given an array of words and a length L, format the text such that each line has exactlyL characters and is fully (left and right) justified.You should pack your words in a greedy approach; that is原创 2015-12-30 16:42:18 · 297 阅读 · 0 评论 -
067 - Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".char* addBinary(char* a, char* b) { int lena = strlen(a); int lenb = strlen(b原创 2015-12-30 16:41:19 · 304 阅读 · 0 评论 -
066 - Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.int* plusOne(int* di原创 2015-12-30 16:40:46 · 289 阅读 · 0 评论 -
065 - Valid Number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguous.原创 2015-12-30 16:38:21 · 306 阅读 · 0 评论 -
064 - Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2015-12-30 16:37:08 · 286 阅读 · 0 评论 -
063 - Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid.原创 2015-12-30 16:35:42 · 296 阅读 · 0 评论 -
062 - Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo原创 2015-12-30 16:34:45 · 275 阅读 · 0 评论 -
061 - Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL./** * Definition for singly-link原创 2015-12-30 16:33:53 · 289 阅读 · 0 评论 -
060 - Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""312""原创 2015-11-27 08:36:20 · 345 阅读 · 0 评论 -
058 - Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defi原创 2015-11-27 08:34:09 · 277 阅读 · 0 评论 -
059 - Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 ton2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [原创 2015-11-27 08:35:28 · 231 阅读 · 0 评论 -
057 - 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原创 2015-11-27 08:33:13 · 252 阅读 · 0 评论 -
056 - 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].int intercmp(const void *a, const void *b){原创 2015-11-27 08:31:36 · 240 阅读 · 0 评论 -
055 - Jump Game
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.Determine if原创 2015-11-26 18:28:07 · 232 阅读 · 0 评论 -
042 - 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]原创 2015-11-25 17:25:10 · 292 阅读 · 0 评论 -
031 - Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible o原创 2015-11-11 18:43:31 · 322 阅读 · 0 评论 -
018 - 4Sum
Given an array S of n integers, are there elements a,b, c, and d in S such that a + b +c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements原创 2015-11-11 17:28:21 · 247 阅读 · 0 评论 -
017 - Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string原创 2015-11-11 17:26:04 · 226 阅读 · 0 评论 -
016 - 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly原创 2015-11-11 17:24:22 · 259 阅读 · 0 评论 -
015 - 3Sum
Given an array S of n integers, are there elements a,b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) m原创 2015-11-11 17:21:59 · 224 阅读 · 0 评论