加载中...

daily leetcode - trapping-rain-water - !

题目地址 https://leetcode.com/problems/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 rain water (blue section) are being trapped. Thanks Marcos for contributing this image! Example: Input: [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 思路 这道收集雨水的题跟之前的那道 Largest Rectangle in Histogr....

daily leetcode - first-missing-positive - !

题目地址 https://leetcode.com/problems/first-missing-positive/ 题目描述 Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2,0] Output: 3 Example 2: Input: [3,4,-1,1] Output: 2 Example 3: Input: [7,8,9,11,12] Output: 1 Note: Your algorithm should run in O ( n ) time and uses constant extra space. 思路 这道题让我们找缺失的首个正数,由于限定了 O(n) 的时间,所以一般的排序方法都不能用,最开始博主没有看到还限制了空间复杂度,所以想到了用 HashSet 来解,这个思路很简单,把所有的数都存入 HashSet 中,然后循环从 1 开始递增找数字,哪个数字找不到就返回哪个数字,如果一直找到了最大的数字(这里是 n....

随笔 2020-2-4

😰 我在做什么? 果然,人都是有惰性的啊,这才坚持几天我就不想继续做下去了,也不是说不想做下去,就今天感觉没有那个心情继续。。 感觉潜意识里把他当成了一个任务,而不是自己想做的一件事情。 果然还是懒惰在犯罪。 少坚持一天,离放弃还有多远呢。 今天的任务不完成,我就..

daily leetcode - combination-sum-ii - !

题目地址 https://leetcode.com/problems/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 numbers (including target) will be positive integers. The solution set must not contain duplicate combinations. Example 1: Input: candidates = [10,1,2,7,6,1,5], target = 8, A solution set is....

daily leetcode - combination-sum - !

题目地址 https://leetcode.com/problems/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 number of times. Note: All numbers (including target) will be positive integers. The solution set must not contain duplicate combinations. Example 1: Input: candidates = [2,3,6,7], target = 7, ....

daily leetcode - count-and-say - !

题目地址 https://leetcode.com/problems/count-and-say 题目描述 The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2, then one 1" or 1211. Given an integer n where 1 ≤ n ≤ 30, generate the n th term of the count-and-say sequence. Note: Each term of the sequence of integers will be represented as a string. Example 1: Input: 1 Output: "1" E....

daily leetcode - sudoku-solver - !

题目地址 https://leetcode.com/problems/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. Each of the the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid. Empty cells are indicated by the character '.'. A sudoku puzzle... ...and its solution numbers m....

daily leetcode - valid-sudoku - !

题目地址 https://leetcode.com/problems/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-9without repetition. Each column must contain the digits 1-9 without repetition. Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition. A partially filled sudoku which is valid. The Sudoku board could be partially filled, where empty cells are filled with ....

daily leetcode - longest-palindromic-substring - !

题目地址 https://leetcode.com/problems/longest-palindromic-substring/description/ 题目描述 Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2: Input: "cbbd" Output: "bb" 思路 这是一道最长回文的题目,要我们求出给定字符串的最大回文子串。 解决这类问题的核心思想就是两个字“延伸”,具体来说 如果一个字符串是回文串,那么在它左右分别加上一个相同的字符,那么它一定还是一个回文串 如果一个字符串不是回文串,或者在回文串左右分别加不同的字符,得到的一定不是回文串 事实上,上面的分析已经建立了大问题和小问题之间的关联, 基于此,我们可以建立....

avatar
Lonus Lan
It's better to burn out than to fade away!
公告
暂无更新通知!
最新文章
网站资讯
文章数目 :
156
已运行时间 :
0 天
本站在线访客数 :
0
本站总访问量 :
0