![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode C++
木车
一个有追求的好人,一个纯粹的技术工作者
展开
-
Leetcode 25. Reverse Nodes in k-Group
原题:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the n原创 2018-01-31 08:48:53 · 90 阅读 · 0 评论 -
Leetcode 28. Implement strStr()
原题:Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2原创 2018-01-31 08:49:13 · 96 阅读 · 0 评论 -
Leetcode 29. Divide Two Integers
原题:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.解决方法:除法的实现,关键在于大循环中的小循环,通过往左移1位倍增被除数来加快速度。代码:int divide(int d原创 2018-01-31 08:49:34 · 96 阅读 · 0 评论 -
Leetcode 26. Remove Duplicates from Sorted Array
原题:Given a sorted array, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modif原创 2018-01-31 08:49:48 · 108 阅读 · 0 评论 -
Leetcode 27. Remove Element
原题:Given an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input arrayi原创 2018-01-31 08:49:57 · 84 阅读 · 0 评论 -
Leetcode 30. Substring with Concatenation of All Words
原题:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) ins that is a concatenation of each word inwords exactly on原创 2018-01-31 08:50:07 · 183 阅读 · 0 评论 -
Leetcode 31. 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 possi原创 2018-01-31 08:50:18 · 124 阅读 · 0 评论 -
Leetcode 32. Longest Valid Parentheses
原题:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()原创 2018-01-31 08:50:26 · 108 阅读 · 0 评论 -
Leetcode 33. Search in Rotated Sorted Array
原题: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).You are given a target value to search. If f原创 2018-01-31 08:50:38 · 109 阅读 · 0 评论 -
Leetcode 34. Search for a Range
原题:Given an array of integers sorted in ascending order, 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).原创 2018-01-31 08:50:46 · 104 阅读 · 0 评论 -
Leetcode 35. Search Insert Position
原题: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 in the arr原创 2018-02-01 09:17:36 · 107 阅读 · 0 评论 -
Leetcode 36. 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 f原创 2018-02-01 09:17:50 · 81 阅读 · 0 评论 -
Leetcode 37. 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 sudok原创 2018-02-01 09:18:03 · 96 阅读 · 0 评论 -
Leetcode 38. Count and Say
原题:The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is rea原创 2018-02-01 09:18:15 · 85 阅读 · 0 评论 -
Leetcode 39. Combination Sum
原题:Given a set of candidate numbers (C)(without duplicates) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen原创 2018-02-01 09:18:27 · 81 阅读 · 0 评论 -
Leetcode 40. 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 toT.Each number in C may only be used once in the combin原创 2018-02-01 09:18:38 · 78 阅读 · 0 评论 -
Leetcode 41. 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 con原创 2018-02-01 09:18:52 · 166 阅读 · 0 评论 -
Leetcode 42. 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原创 2018-02-01 09:19:03 · 133 阅读 · 0 评论 -
Leetcode 43. Multiply Strings
原题:Given two non-negative integers num1 and num2 represented as strings, return the product ofnum1 andnum2.Note:The length of both num1 and num2 is Both num1 and num2 contains only digits 0-原创 2018-02-01 09:19:17 · 112 阅读 · 0 评论 -
Leetcode 44. Wildcard Matching
原题:mplement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cov原创 2018-02-01 09:19:27 · 141 阅读 · 0 评论 -
Leetcode 45. 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 g原创 2018-02-02 08:43:58 · 84 阅读 · 0 评论 -
Leetcode 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,1,2], [3,原创 2018-02-02 08:44:10 · 87 阅读 · 0 评论 -
Leetcode 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], [1,2,1], [原创 2018-02-02 08:44:17 · 78 阅读 · 0 评论 -
Leetcode 48. Rotate Image
原题:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D mat原创 2018-02-02 08:44:25 · 92 阅读 · 0 评论 -
Leetcode 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"]]Note: A原创 2018-02-02 08:44:33 · 102 阅读 · 0 评论 -
Leetcode 50. Pow(x, n)
原题:mplement pow(x, n).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100解决方法:用递归的方法来解这道题,每次将幂除以2,如果当前幂是偶数,则结果刚好是递归结果的平方。如果当前幂是奇数,则需要根据幂的正负数来原创 2018-02-02 08:44:42 · 88 阅读 · 0 评论 -
Leetcode 51. 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 puzz原创 2018-02-02 08:45:02 · 102 阅读 · 0 评论 -
Leetcode 52. N-Queens II
原题:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.解决方法:跟前面一道题的解题思路完全一样,而且只需要将结果保存到一个数组里面,最后返回数组的大小即可。原创 2018-02-02 08:45:12 · 104 阅读 · 0 评论 -
Leetcode 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 subarray [4,-1,2,1]原创 2018-02-02 08:45:19 · 96 阅读 · 0 评论 -
Leetcode 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, 9 ]原创 2018-02-02 08:45:26 · 98 阅读 · 0 评论 -
Leetcode 1. Two Sum
原题:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use th原创 2018-01-26 16:40:04 · 84 阅读 · 0 评论 -
Leetcode 2. Add Two Numbers
原题:You are given two non-empty linked lists representing two non-negative integers. The digits are stored inreverse order and each of their nodes contain a single digit. Add the two numbers an原创 2018-01-26 16:54:16 · 85 阅读 · 0 评论 -
Leetcode 3. Longest Substring Without Repeating Characters
原题:Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer i原创 2018-01-26 17:20:34 · 91 阅读 · 0 评论 -
Leetcode 4. Median of Two Sorted Arrays
原题:There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1原创 2018-01-26 17:52:09 · 89 阅读 · 0 评论 -
Leetcode 55. 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原创 2018-02-03 08:27:38 · 91 阅读 · 0 评论 -
Leetcode 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].解决方法:毫无疑问,首先需要对数组进行排序。然后从后往前,依次合并原创 2018-02-03 08:27:49 · 80 阅读 · 0 评论 -
Leetcode 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 start time原创 2018-02-03 08:28:01 · 156 阅读 · 0 评论 -
Leetcode 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.Note: A word is d原创 2018-02-03 08:28:11 · 87 阅读 · 0 评论 -
Leetcode 59. 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原创 2018-02-03 08:28:22 · 99 阅读 · 0 评论 -
Leetcode 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""132""213""2原创 2018-02-03 08:28:33 · 90 阅读 · 0 评论