1129. 颜色交替的最短路径
问题1129 颜色交替的最短路径 ★★☆☆☆ https://leetcode.cn/problems/shortest-path-with-alternating-colors/ 这个题目可是费了不少的时间和精力。从解题入手点来说,大的思路并不难,比较容易想到可以通过广度优先遍历(BFS)来解决这个问题。问题的关键在于每一层BFS具体做哪些操作?这可以从循环不变量来入手。我一开始的思路是...
问题1129 颜色交替的最短路径 ★★☆☆☆ https://leetcode.cn/problems/shortest-path-with-alternating-colors/ 这个题目可是费了不少的时间和精力。从解题入手点来说,大的思路并不难,比较容易想到可以通过广度优先遍历(BFS)来解决这个问题。问题的关键在于每一层BFS具体做哪些操作?这可以从循环不变量来入手。我一开始的思路是...
问题1091 二进制矩阵中的最短路径 ★★☆☆☆ https://leetcode-cn.com/problems/shortest-path-in-binary-matrix/ 这个题目和问题542、问题994很类似,稍有区别就是这个题目是可以斜着遍历,即可以以相邻点做遍历,而不限于相邻边。简单来说就是从源点开始按宽度做扩散,每次处理一批距离源点相同宽度的0点,判断这些0点中是否已经扩散...
How is Redis different from other key-value stores? Redis has a different evolution path in the key-value DBs where values can contain more complex data types, with atomic operations defined on ...
Redis keys are binary safe, this means that you can use any binary sequence as key, from a string like “foo” to the content of a JPEG file. The empty string is also a valid key. The maximum allowed...
问题844 比较含退格的字符串 ★☆☆☆☆ https://leetcode-cn.com/problems/backspace-string-compare/ 这个题目最直接的思路就是按照backspace规则,分别把两个字符串做backspace处理,然后比较得到的结果。代码并不复杂,提交以后也通过了。这种处理的时间复杂度和空间复杂度都是O(N). 那么题目中附加的能不能以O(1)的...
问题713 乘积小于K的子数组 ★★☆☆☆ https://leetcode-cn.com/problems/subarray-product-less-than-k/ 这个题目其实和问题209很像,利用滑动窗口来解答的思路都是,先向右扩展右指针,直到左右指针窗口内的元素不再满足某个要求,开始向右扩展左指针,在这个过程中,维护一个目标计算结果。 public int numSubarr...
问题567 字符串的排列 ★★☆☆☆ https://leetcode-cn.com/problems/permutation-in-string/ 这个题目和问题438几乎是一样的,相比问题438还更简单些,只需要判断是否存在子串即可,不再赘述。 public boolean checkInclusion(String s1, String s2) { int len1 = s1...
问题557 反转字符串中的单词 ★☆☆☆☆ https://leetcode-cn.com/problems/reverse-words-in-a-string-iii/ 这个题目从思路上讲,没有什么难度,最直接的处理可以把字符串转换为字符数组,然后遍历该数组,如果不是空格,将字符加到一个临时字符串中;如果是空格,则反转临时字符串并添加到结果字符串中,然后把空格也加入结果字符串。 这里使...
问题438 找到字符串中所有字母异位词 ★★☆☆☆ https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/ 这个题目可以从暴力解法的思路入手,即顺序遍历所有子串,判断每个子串是不是p的anagram. 第一个关键点,如何判断一个子串是不是p的anagram呢?比较直接的思路是使用两个计数数组,分别计数两个字符串中每个字...
问题344 反转字符串 ☆☆☆☆☆ https://leetcode-cn.com/problems/reverse-string/ 无需赘述。 public void reverseString(char[] s) { for (int i = 0, j = s.length - 1; i < j; i++, j--) { char tmp = s[i]; s[...