![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 66
jinglingli_SJTU
悟以往之不谏,知来者之可追
展开
-
71. Simplify Path
problem:Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"这道题的要求是简化一个Unix风格下的文件的绝对路径。需注意以下几种情况:1.重原创 2017-01-25 11:15:21 · 221 阅读 · 0 评论 -
68. Text Justification
problem: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 ap原创 2017-01-15 13:46:30 · 260 阅读 · 0 评论 -
67. Add Binary
problem:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".这道题首先补齐较短的那个字符串,然后循环遍历即可class Solution {public: string addBin原创 2017-01-08 21:13:52 · 255 阅读 · 0 评论 -
66. Plus One
problem: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 itsel原创 2017-01-08 20:56:26 · 267 阅读 · 0 评论 -
65. Valid Number
problem: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原创 2017-01-08 14:10:27 · 280 阅读 · 0 评论 -
64. Minimum Path Sum
problem: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 do原创 2017-01-04 21:55:49 · 247 阅读 · 0 评论 -
63. Unique Paths II
problem: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 respecti原创 2017-01-04 21:01:54 · 194 阅读 · 0 评论 -
62. Unique Paths
problem: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-01-04 20:18:56 · 222 阅读 · 0 评论 -
60. Permutation Sequence
problem: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""13原创 2016-12-15 16:50:18 · 248 阅读 · 0 评论 -
57. Insert Interval
problem: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 sta原创 2016-12-14 11:22:45 · 256 阅读 · 0 评论 -
61. Rotate List
problem: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.将链表首尾相连成环。寻找尾节点的同时可原创 2016-12-15 19:41:43 · 496 阅读 · 0 评论 -
69. Sqrt(x)
problem:Implement int sqrt(int x).Compute and return the square root of x.本问题是完成开根号的操作。这道题使用二分查找,因为是求数x(x>=0) 的平方根, 因此,结果一定是小于等于x且大于等于0,所以用二分查找法肯定能搜到结果。以每一次的mid的平方来与target既数x相比:如原创 2017-01-15 13:56:27 · 352 阅读 · 0 评论 -
70. Climbing Stairs
problem: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原创 2017-01-15 14:11:16 · 235 阅读 · 0 评论 -
72. Edit Distance
problem: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 permit原创 2017-02-09 10:49:13 · 280 阅读 · 0 评论 -
81. Search in Rotated Sorted Array II
problem:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Write a function to determine if原创 2017-02-11 16:07:11 · 289 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II
problem:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5原创 2017-02-11 10:28:11 · 438 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
problem:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, wit原创 2017-02-10 21:29:51 · 350 阅读 · 0 评论 -
79. Word Search
problem:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally原创 2017-02-10 20:58:59 · 278 阅读 · 0 评论 -
78. Subsets
problem:Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[原创 2017-02-10 16:27:33 · 260 阅读 · 0 评论 -
77. Combinations
problem:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,原创 2017-02-10 15:54:29 · 239 阅读 · 0 评论 -
76. Minimum Window Substring
problem:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum原创 2017-02-09 17:42:37 · 325 阅读 · 0 评论 -
75. Sort Colors
problem: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原创 2017-02-09 16:48:40 · 295 阅读 · 0 评论 -
74. Search a 2D Matrixp
problem: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 i原创 2017-02-09 15:57:58 · 345 阅读 · 0 评论 -
73. Set Matrix Zeroes
problem:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is原创 2017-02-09 11:18:57 · 395 阅读 · 0 评论 -
56. Merge Intervals
problem: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].1.先将目标区间数组按X轴从小到大排序,2.扫描排序后的目标区间数组,将原创 2016-12-13 12:28:21 · 230 阅读 · 0 评论 -
55. Jump Game
problem: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.原创 2016-12-13 11:33:55 · 289 阅读 · 0 评论 -
50. Pow(x, n)
problem:Implement pow(x, n).此题为求解x的n次幂。此题的解题思路比较简单:将n次幂“折半”,即:Pow(x,n)=Pow(x,n/2)*Pow(x,n/2)或者Pow(x,n)=Pow(x,n/2)*Pow(x,n/2)*x,如此往复,则可降低时间复杂度,但要注意边界条件的处理:1.幂n=0,返回1.0;2.基x=0,返回0.0;3.幂n<0原创 2016-12-06 22:24:59 · 279 阅读 · 0 评论 -
53. Maximum Subarray
problem: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原创 2016-12-12 09:54:14 · 380 阅读 · 0 评论 -
51. N-Queens
problem: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-que原创 2016-12-11 17:33:11 · 199 阅读 · 0 评论 -
38. Count and Say
problem: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 i原创 2016-12-01 14:26:05 · 300 阅读 · 0 评论 -
37. Sudoku Solver
problem:该问题是数独求解问题,采用方法是深度搜索优先算法。class Solution {private: bool isOver; //是否已经找到一个正确解。 public: void dfs(vector>& board, int i, int j, int n) { if(j >= n) {原创 2016-12-01 11:00:28 · 238 阅读 · 0 评论 -
36. Valid Sudoku
problem: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 '.'.该问题是判断该数独原创 2016-12-01 09:31:31 · 242 阅读 · 0 评论 -
35. Search Insert Position
problem:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates原创 2016-11-30 16:51:59 · 272 阅读 · 0 评论 -
34. Search for a Range
problem:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target原创 2016-11-30 16:20:59 · 206 阅读 · 0 评论 -
33. Search in Rotated Sorted Array
problem:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in t原创 2016-11-30 12:41:03 · 346 阅读 · 0 评论 -
32. Longest Valid Parentheses
problem:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substri原创 2016-11-29 21:03:02 · 330 阅读 · 0 评论 -
31.Next Permutation
Promblem:题意为寻找比当前序列大的新序列。那什么叫比前序列大呢?其实可以把数字序列理解为多位数字,对于n位序列,可以组成n!个数字,那么所谓的序列大就是新序列的数值大小比旧的序列大,并且是所有满足条件中的数值中最小的那一个。所以要满足两个条件:1.新序列要比旧的序列大;2.新序列要是所有可行序列中最小的一个。想到自己以前枚举由小到大的序列时,一般思路为先确定高位,然原创 2016-11-29 09:16:21 · 363 阅读 · 0 评论 -
39. Combination Sum
problem: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原创 2016-12-02 21:50:51 · 275 阅读 · 0 评论 -
40. Combination Sum II
problem: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原创 2016-12-02 22:37:09 · 218 阅读 · 0 评论 -
41. First Missing Positive
problem: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原创 2016-12-02 22:40:22 · 193 阅读 · 0 评论