- 博客(69)
- 资源 (2)
- 收藏
- 关注
原创 leetcode 075 —— Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers
2015-07-31 16:32:06 179
原创 leetcode 074 —— Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each
2015-07-31 15:37:47 181
原创 leetcode 073 —— Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.思路:用两个一维数组存储 有 0 的位置class Solution {public: void setZeroes(vector>& matrix) { int m = matrix.size
2015-07-31 11:02:11 302
原创 leetcode 072 —— Edit Distance
Given 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 following 3 operations permitted on a word:
2015-07-31 10:47:37 197
原创 leetcode 071 —— Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"思路:字符串的处理,把/ /中间的字符串剔出进行删选判断,但是结果很奇怪,/...输出是/...,这个不是很理解
2015-07-30 21:06:59 253
原创 leetcode 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?思路:一维简单动态规划class S
2015-07-30 17:08:00 257
原创 leetcode 068 —— Text Justification
Given 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 in a greedy approach; that i
2015-07-29 21:09:34 247
原创 leetcode 067 —— Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".思路:类似大数相加class Solution {public: string addBinary(string a, string b) { in
2015-07-29 19:17:00 267
原创 leetcode 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.思路:模拟整数的加法,这个比较简单
2015-07-29 15:43:39 257
原创 leetcode 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 ambiguo
2015-07-29 15:11:21 270
原创 leetcode 064 —— Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at
2015-07-28 15:26:57 254
原创 leetcode 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
2015-07-28 15:04:17 283
原创 leetcode 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
2015-07-28 14:38:44 285
原创 leetcode 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.思路:
2015-07-28 10:56:43 348
原创 leetcode 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""3
2015-07-27 18:43:55 271
原创 leetcode 059 —— Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2015-07-27 15:34:15 253
原创 leetcode 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
2015-07-27 15:02:40 204
原创 leetcode 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.E
2015-07-27 14:39:12 219
原创 leetcode 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].思路:
2015-07-24 15:25:34 177
原创 leetcode 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 i
2015-07-23 19:44:16 212
原创 leetcode 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 ]]
2015-07-23 19:35:45 273
原创 leetcode 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]
2015-07-23 19:28:17 196
原创 leetcode 052 —— N-Queens II
计算不同的排列个数思路同上class Solution {public: int totalNQueens(int n) { vector queen(n,-1); int count = 0; scan(0, count,n,queen); return count; } bool isLegal(int x, int y, vector &queen){
2015-07-23 19:14:37 248
原创 leetcode 050 —— 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.Given an integer n, return all distinct solutions to the n-queens puzzle.
2015-07-23 19:09:49 168
原创 leetcode 050 —— Pow(x, n)
Implement pow(x, n).思路:实现指数运算,如果直接使用乘法,会超时。 采用二分法计算 时间复杂度 log(n)class Solution {public: double myPow(double x, int n) { if (n == 0) return 1.0; if (n<0) return 1.0 / pow(x, -n);
2015-07-23 16:53:03 211
原创 leetcode 048 —— Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.题意:找到重构的字符串For example:Input: ["tea","and","ate","eat","den"]Outpu
2015-07-23 16:40:17 265
原创 leetcode 048 —— Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).思路:两个for循环即可class Solution {public: void rotate(vector>& matrix) { if (matrix.empty())
2015-07-23 15:35:44 305
原创 leetcode 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-07-23 15:31:54 299
原创 leetcode 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].思路:递归咯c
2015-07-23 15:25:41 419
原创 leetcode 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 i
2015-07-23 15:18:17 248
原创 leetcode 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 t
2015-07-23 14:54:37 509
原创 leetcode 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.思路:
2015-07-19 10:47:26 224
原创 leetcode 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-07-17 19:36:49 171
原创 leetcode 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
2015-07-17 11:01:31 272
原创 leetcode 040 —— Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina
2015-07-16 13:37:34 250
原创 leetcode 038 —— Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb
2015-07-15 22:16:13 161
原创 leetcode 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
2015-07-15 21:45:46 231
原创 leetcode 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
2015-07-15 21:42:53 172
原创 leetcode 035 —— 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 fille
2015-07-15 17:26:02 182
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人