
leetcode
文章平均质量分 86
csdn0006
公众号:深度学习黑板报
展开
-
leetcode-hot100-普通数组
当遍历到非第一个元素时,比较res数组的最后一个区间的右边界和当前区间的左边界,如果重合,即res[-1][1] < intervals[i][0], 进行区间合并,将res中最后一个区间的右边界更新为当前元素的右边界;如果不重合,直接加入到结果数组中。dp[i]的计算和dp[i-1], nums[i]有关,也可以把dp数组去掉,使用pre、cur来代替,pre=dp[i-1], cur=dp[i],节省空间。**输入:intervals = [[1,3],[2,6],[8,10],[15,18]]原创 2024-03-10 23:04:31 · 874 阅读 · 0 评论 -
【每日一题】48. Rotate Image
问题描述You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotati原创 2020-10-28 23:31:18 · 171 阅读 · 0 评论 -
【每日一题】46. Permutations
题目描述Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]给定一个 没有重复 数字的序列,返回其所有可能的全排列。题解典型的递归问题。1、2、 3的全排列,可以分为以1开头,2、 3的全排列;2开头,1原创 2020-09-08 23:37:56 · 208 阅读 · 0 评论 -
【每日一题】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 goal is to reach the last index in the minimum number of jumps.原创 2020-09-07 23:31:52 · 185 阅读 · 0 评论 -
【每日一题】43. Multiply Strings
题目描述Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.Example 1:Input: num1 = "2", num2 = "3"Output: "6"Example 2:Input: num1 = "123", num2 = "456"Output: "56088"原创 2020-09-01 00:00:25 · 176 阅读 · 0 评论 -
【每日一题】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.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of原创 2020-08-25 23:27:22 · 215 阅读 · 0 评论 -
【每日一题】41. First Missing Positive
问题描述Given an unsorted integer array, find the smallest missing positive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Output: 2Example 3:Input: [7,8,9,11,12]Output: 1Follow up:Your algorithm should run in O(n) time and原创 2020-08-24 23:43:26 · 174 阅读 · 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 may only be used once in the combination.Note:All nu原创 2020-08-23 22:02:05 · 181 阅读 · 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 repeated number may be chosen from candidates unlimited nu原创 2020-08-20 22:23:57 · 203 阅读 · 0 评论 -
【每日一题】37. Sudoku Solver
题目描述Write a program to solve a Sudoku puzzle by filling the empty cells.A sudoku solution must satisfy all of the following rules:Each of the digits 1-9 must occur exactly once in each row.Each of the digits 1-9 must occur exactly once in each column.原创 2020-08-16 21:47:06 · 222 阅读 · 0 评论 -
【每日一题】36. Valid Sudoku
题目描述Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.Each column must contain the digits 1-9 without repetition.Each of the 9原创 2020-08-10 23:47:56 · 254 阅读 · 0 评论 -
【每日一题】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 array.Example 1:Input: [1,3,5,6], 5Output: 2Example 2:原创 2020-08-09 23:11:19 · 129 阅读 · 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 the target is not found in the array, return [-1, -1].E原创 2020-08-08 23:55:38 · 277 阅读 · 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 found in the array return its index, otherwise return -1.Y原创 2020-08-05 23:36:24 · 217 阅读 · 0 评论 -
【每日一题】32. Longest Valid Parentheses
题目描述Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest valid parentheses substring is "()"Example 2:Input: ")()原创 2020-08-04 23:23:54 · 174 阅读 · 0 评论 -
【每日一题】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 possible order (ie, sorted in ascending order).The replacemen原创 2020-07-31 23:36:22 · 185 阅读 · 0 评论 -
【每日一题】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) in s that is a concatenation of each word in words exactly once and without any intervening characters.Example 1:Input:原创 2020-07-30 23:11:05 · 253 阅读 · 0 评论 -
【每日一题】29. Divide Two Integers
题目描述Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The integer division should truncate toward zero, which means losing its frac原创 2020-07-29 23:58:29 · 881 阅读 · 0 评论 -
【每日一题】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: 2Example 2:Input: haystack = "aaaaa", needle = "bba"Output: -1原创 2020-07-28 22:58:37 · 174 阅读 · 0 评论 -
【每日一题】27. Remove Element
题目描述Given an array nums and a value val, 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 array in-place with O(1) extra memory.The order of elem原创 2020-07-27 22:35:09 · 167 阅读 · 0 评论 -
【LeetCode每日一题】26. Remove Duplicates from Sorted Array
题目描述Given a sorted array nums, 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 modifying the input array in-place with O(1) extra memory.原创 2020-07-27 07:47:28 · 184 阅读 · 0 评论 -
【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 number of nodes is not a multiple of k then left-out nodes in原创 2020-07-25 23:01:29 · 112 阅读 · 0 评论 -
【LeetCode每日一题】24. Swap Nodes in Pairs
问题描述Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list’s nodes, only nodes itself may be changed.Example:Given 1->2->3->4, you should return the list as 2->1->4->3.给定一个链表原创 2020-07-24 22:52:59 · 135 阅读 · 0 评论 -
【LeetCode每日一题】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->4->5->6合并k个有序单链表,然后返回这个新链表。分析时间复杂度、空间复杂度。原创 2020-07-23 22:59:43 · 199 阅读 · 0 评论 -
【LeetCode每日一题】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:[ "((()))", "(()())", "(())()", "()(())", "()()()"]数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且原创 2020-07-22 18:30:10 · 173 阅读 · 0 评论 -
【LeetCode每日一题】21. Merge Two Sorted Lists
题目描述Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1->1->2->3->4->4通过合并两个有序链表生成一个新的原创 2020-07-21 22:48:31 · 190 阅读 · 0 评论 -
11. Container With Most Water
题意给定n个非负整数a1,a2,...,ana_1,a_2,...,a_na1,a2,...,an,其中每个数表示坐标点(i,ai)(i,a_i)(i,ai),i是数组下标,aia_iai是对应高度.寻找两条线,使得两条线构成的长方形面积最大,盛水最多.Example:Input: [1,8,6,2,5,4,8,3,7]Output: 49解暴力破解对每种情况进行循环,计...原创 2018-12-17 22:25:22 · 129 阅读 · 0 评论