![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
刷题
刷题日记
saomanchum
这个作者很懒,什么都没留下…
展开
-
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 number...原创 2020-02-20 22:27:02 · 80 阅读 · 0 评论 -
23. Merge k Sorted Lists
题目描述Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[1->4->5,1->3->4,2->6]Output: 1->1->2->3->4->...原创 2020-02-17 22:03:23 · 66 阅读 · 0 评论 -
22. Generate Parentheses
题目描述Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[“((()))”,“(()())”,“(())()”,“()(())”,“()(...原创 2020-02-17 21:11:58 · 58 阅读 · 0 评论 -
20. Valid Parentheses
题目描述Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type o...原创 2020-02-14 01:28:57 · 65 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number
题目描述Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is...原创 2020-02-14 01:11:12 · 59 阅读 · 0 评论 -
14. Longest Common Prefix
题目描述Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string “”.Example 1:Input: [“flower”,“flow”,“flight”]Output...原创 2020-02-14 00:18:08 · 55 阅读 · 0 评论 -
12. Integer to Roman 13. Roman to Integer
12. Integer to Roman题目描述Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C ...原创 2020-02-12 23:33:43 · 91 阅读 · 0 评论 -
92. Reverse Linked List II
题目描述Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5...原创 2020-02-12 23:03:35 · 108 阅读 · 0 评论 -
86. Partition List
题目描述Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each ...原创 2020-02-12 00:26:01 · 84 阅读 · 0 评论 -
81. Search in Rotated Sorted Array II
题目描述Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]).You are given a target value to search. If fou...原创 2020-02-10 14:24:56 · 84 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
题目描述Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.Do not allocate extra space for another array, you must do this by...原创 2020-02-06 21:49:31 · 69 阅读 · 0 评论 -
79. Word Search
题目描述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 or vertical...原创 2020-02-06 17:16:57 · 77 阅读 · 0 评论 -
78. Subsets
题目描述Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[[3],[1],...原创 2020-01-31 22:58:32 · 73 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II
题目描述Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output: 1-&...原创 2020-01-30 20:30:15 · 71 阅读 · 0 评论 -
61. Rotate List
题目描述Given a linked list, rotate the list to the right by k places, where k is non-negative.Example 1:Input: 1->2->3->4->5->NULL, k = 2Output: 4->5->1->2->3->NULLExpl...原创 2020-01-29 23:56:02 · 76 阅读 · 0 评论 -
剑指:二叉树的下一节点
题目描述给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。解题思路这道题主要考察的是对中序遍历的熟悉程度。考虑三种情况如果该节点有右子树,则它的下一个节点应该在其右子树的最左子节点。如果该节点没有右子树,且其为其父节点的左子树,则其下一个节点为其父节点如果该节点没有右子树且为父节点的右子树,则回溯他...原创 2020-01-29 23:10:45 · 75 阅读 · 0 评论 -
剑指:重建二叉树
题目描述输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。解题思路在前序序列中,第一个数为root节点,而紧接着的是左子树的root节点。在中序序列中,通过遍历找到root节点所在位置,因为在中序序列中ro...原创 2020-01-29 22:24:52 · 58 阅读 · 0 评论 -
DFS
这个好原创 2020-01-28 16:35:21 · 74 阅读 · 0 评论 -
75. Sort Colors
题目描述Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use th...原创 2020-01-28 13:54:55 · 120 阅读 · 0 评论 -
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 integer of each ...原创 2020-01-28 13:03:26 · 68 阅读 · 0 评论 -
73. 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.Example 1:Input:[[1,1,1],[1,0,1],[1,1,1]]Output:[[1,0,1],[0,0,0],[1,0,1]]解题思路好聪明的做法先扫...原创 2020-01-28 00:02:05 · 71 阅读 · 0 评论 -
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 down or right ...原创 2020-01-27 22:13:26 · 64 阅读 · 0 评论 -
63. Unique Paths II
题目描述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 th...原创 2020-01-27 21:54:14 · 618 阅读 · 0 评论 -
59. Spiral Matrix II
题目描述Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.Example:Input: 3Output:[[ 1, 2, 3 ],[ 8, 9, 4 ],[ 7, 6, 5 ]]解题思路想法是之前那个[Spiral Mat...原创 2020-01-27 18:18:48 · 77 阅读 · 0 评论 -
56. Merge Intervals
题目描述Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overla...原创 2020-01-27 14:43:42 · 70 阅读 · 0 评论 -
19. Remove Nth Node From End of List
题目描述Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, ...原创 2020-01-17 19:33:36 · 81 阅读 · 0 评论 -
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.Determine i...原创 2020-01-17 17:33:38 · 72 阅读 · 0 评论 -
54. Spiral Matrix
题目描述Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Example 1:Input:[[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]解题...原创 2020-01-17 16:25:24 · 79 阅读 · 0 评论 -
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 matrix...原创 2020-01-16 13:54:40 · 85 阅读 · 0 评论 -
40. Combination Sum II
题目描述Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.Each number in candidates...原创 2020-01-15 17:02:01 · 71 阅读 · 0 评论 -
39. Combination Sum
题目描述Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same re...原创 2020-01-15 16:21:46 · 66 阅读 · 0 评论 -
31. Next Permutation
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...原创 2020-01-15 14:51:58 · 75 阅读 · 0 评论 -
18. 4Sum
18. 4Sum题目描述:Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives...原创 2020-01-14 16:46:24 · 54 阅读 · 0 评论 -
16. 3Sum Closest
3Sum Closest题目描述Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume th...原创 2020-01-14 15:40:31 · 53 阅读 · 0 评论 -
34. Find First and Last Position of Element in Sorted Array
题目描述Given an array of integers nums 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).If ...原创 2020-01-11 00:49:01 · 65 阅读 · 0 评论 -
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 fou...原创 2020-01-10 22:44:50 · 60 阅读 · 0 评论 -
15. 3sum
题目描述Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.方法选定一个数,剩下的就是找two sum的事情了。但是two ...原创 2020-01-10 00:42:40 · 56 阅读 · 0 评论