- 博客(31)
- 收藏
- 关注
原创 74.二维数组中找数
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
2017-08-30 11:52:20 225
原创 73.设置数组为0
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.测试代码(Python):class Solution(object): def setZeroes(self, matrix): """
2017-08-29 09:39:41 457
原创 72.单词转变
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 permitt
2017-08-28 09:56:16 196
原创 71.简化路径
Simplify Path问题描述:Given an absolute path for a file (Unix-style), simplify it.For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c”测试代码(c++):class Solution {public: string s
2017-08-27 13:40:36 362
原创 70.爬楼梯
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?Note: Given n wil
2017-08-26 13:10:02 336
原创 69.平方根函数
Sqrt(x)问题描述:Implement int sqrt(int x).Compute and return the square root of x.参考答案(c++):class Solution {public: int mySqrt(int x) { long r = x; while (r*r > x) r = (r +
2017-08-26 12:58:08 360
原创 68.文本格式化
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 greed
2017-08-25 15:21:19 223
原创 67.二进制加法
Add Binary问题描述:Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.参考答案(python):class Solution(object): def addBinary(self, a, b):
2017-08-24 10:17:02 854
原创 66.
Plus One问题描述:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The
2017-08-24 10:01:37 231
原创 65.验证数字
Valid Number问题描述:Validate if a given string is numeric.Some examples: “0” => true ” 0.1 ” => true “abc” => false “1 a” => false “2e10” => true Note: It is intended for the problem statement to be
2017-08-23 10:44:06 198
原创 64.最小路径和
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
2017-08-22 09:59:43 787
原创 63.寻找路径第二弹
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 respectivel
2017-08-21 17:01:30 197
原创 62.寻找路径
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 t
2017-08-20 11:19:13 176
原创 61.链表旋转
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.测试代码(python):# Definition
2017-08-18 10:53:44 293
原创 60.全排列
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” “
2017-08-17 14:57:17 176
原创 59.螺旋数组第二弹
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
2017-08-16 10:31:33 142
原创 58.最后单词的长度
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.No
2017-08-15 11:57:10 962
原创 57.插入间隔
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 st
2017-08-14 11:53:55 264
原创 56.合并间隔
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].知识补充:自定义sort函数sort(intervals.begin(), i
2017-08-13 11:09:35 246
原创 55.jump游戏
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.Determ
2017-08-12 10:49:01 163
原创 54.螺旋读取数组
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,
2017-08-11 14:51:37 242
原创 53.最大子数组
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 subarr
2017-08-10 14:58:27 140
原创 52.多皇后问题第二弹
N-Queens II问题描述:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. 测试代码(C++):int totalNQueens(int n) { vector<bool> col(n,
2017-08-09 11:05:15 136
原创 51.多皇后问题
#问题描述: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.Each
2017-08-07 17:08:11 179
原创 50.实现幂函数
问题描述:Implement pow(x, n).参考答案:class Solution {public: double myPow(double x, int n) { double ans = 1; unsigned long long p; if (n < 0) { p = -n; x =
2017-08-07 11:26:30 272
原创 49.字符串分类
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"]]知识补充
2017-08-06 14:54:03 190
原创 48.图像旋转
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?测试代码:class Solution {public: void rotate(v
2017-08-05 11:00:11 144
原创 47.排列组合第二弹
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],
2017-08-04 10:42:32 156
原创 46.排列的所有可能组合
Permutations问题描述:Given a collection of distinct 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
2017-08-03 14:28:12 363
原创 45.jump游戏第二弹
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.You
2017-08-02 13:00:06 231
原创 44.通配符匹配
Wildcard Matching问题描述:Implement wildcard pattern matching with support for ‘?’ and ‘*’.‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence).The match
2017-08-01 15:19:26 203
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人