加载中...

daily leetcode - word-search - !

题目地址 https://leetcode.com/problems/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 vertically neighboring. The same letter cell may not be used more than once. For example, Given board = [ ["ABCE"], ["SFCS"], ["ADEE"] ] word = "ABCCED", -> returns true, word = "SEE", -> returns true, word = "ABCB", -> returns false. 思路 这道题是典型的深度优先遍....

daily leetcode - subsets - !

题目地址 https://leetcode.com/problems/subsets/ 题目描述 Given a set of distinct integers, S , return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If S = [1,2,3], a solution is: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] 思路 这道求子集合的问题,由于其要列出所有结果,按照以往的经验,肯定要是要用递归来做。这道题其实它的非递归解法相对来说更简单一点,下面我们先来看非递归的解法,由于题目要求子集合中数字的顺序是非降序排列的,所有我们需要预处理,先给输入数组排序,然后再进一步处理,最开始我在想的时候,是想按照子集的长度由少到多全部写出来,比如子集长度为 0 的就是....

daily leetcode - combinations - !

题目地址 https://leetcode.com/problems/combinations/ 题目描述 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,3], [1,4], ] 思路 这道题让求 1 到 n 共 n 个数字里 k 个数的组合数的所有情况,还是要用深度优先搜索 DFS 来解,根据以往的经验,像这种要求出所有结果的集合,一般都是用 DFS 调用递归来解。那么我们建立一个保存最终结果的大集合 res,还要定义一个保存每一个组合的小集合 out,每次放一个数到 out 里,如果 out 里数个数到了 k 个,则把 out 保存到最终结果中,否则在下一层中继续调用递归。网友u010500263 的博客里有一张图很好的说明了递归调用的顺序,请点击这里。 关键点解析 代码 解法一: cl....

daily leetcode - minimum-window-substring - !

题目地址 https://leetcode.com/problems/minimum-window-substring/ 题目描述 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). Example: Input: S = "ADOBECODEBANC", T = "ABC" Output: "BANC" Note: If there is no such window in S that covers all characters in T, return the empty string "". If there is such window, you are guaranteed that there will always be only one unique minimum window in S. 思路 这道题给了我们一个原字符串 S,还有一个目标字符串 T,让在 S 中找....

随笔 2020-2-23

👍 今天是个重要的日子 终于,电脑坏了两周之后,在昨天找到了一家开门的维修店铺,在今天下午一点多拿到了修好的电脑,花了我两百大洋!哈哈,很明显,我被宰了。宰了就宰了吧,反正这电脑我最多还用一年,希望他还能坚持一年的时间吧。 刚刚回来的时候,遇到了一件不愉快的事情。最近肺炎当道,于是限制出行,在出去的单元门口设置了卡口,有一些自以为是的掌握了些许权力的人们趾高气昂的秀着他们肩上的红袖章,对过往路人登记排查。登记询问我理解,但是你别摆出一副此山是我开,此树是我栽的态度行吗? 不过还有什么能比有电脑好的事情更让我现在高兴的事情呢? 先去撸点代码先,两周没写,甚是想念啊!!

我在 GitHub 上的开源项目

daily-leetcode Java 🤩1  ⭐️ 0  🖖0 daily leecode problem pratice 2. lonuslan.github.io JavaScript 🤩0  ⭐️ 0  🖖0 this is my own blog site 3. blog Java 🤩0  ⭐️ 0  🖖0 this is a SpringBoot blog project created by lonuslan in 2019.7.11

daily leetcode - sort-colors - !

题目地址 https://leetcode.com/problems/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 the integers 0, 1, and 2 to represent the color red, white, and blue respectively. Note: You are not suppose to use the library's sort function for this problem. Example: Input: [2,0,2,1,1,0] Output: [0,0,1,1,2,2] Follow up: A rather straight forwa....

daily leetcode - search-a-2d-matrix - !

题目地址 https://leetcode.com/problems/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 row is greater than the last integer of the previous row. Example 1: Input: matrix = [ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50] ] target = 3 Output: true Example 2: Input: matrix = [ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50] ] ....

daily leetcode - set-matrix-zeroes - !

题目地址 https://leetcode.com/problems/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] ] Example 2: Input: [ [0,1,2,0], [3,4,5,2], [1,3,1,5] ] Output: [ [0,0,0,0], [0,4,5,0], [0,3,1,0] ] Follow up: A straight forward solution using O(m**n) space is probably a bad idea. A simple improvement uses O(m + n) space, but still not the best solution. Coul....

daily leetcode - edit-distance - !

题目地址 https://leetcode.com/problems/edit-distance/ 题目描述 Given two words word1 and word2 , find the minimum number of operations required to convert word1 to word2. You have the following 3 operations permitted on a word: Insert a character Delete a character Replace a character Example 1: Input: word1 = "horse", word2 = "ros" Output: 3 Explanation: horse -> rorse (replace 'h' with 'r') rorse -> rose (remove 'r') rose -> ros (remove 'e') Example 2: Input: word1 = "intention", word2 = "....

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