This repository contains the solutions and explanations to the algorithm problems on LeetCode. Only medium or above are included. All are written in C++/Python and implemented by myself. The problems attempted multiple times are labelled with hyperlinks. Topics algorithms leetcode cpp Resources Re...
通过前后指针之差是否等于所有目标单词长度之和来判断是否有目标子字符串。 参考:https://shenjie1993.gitbooks.io/leetcode-python/030%20Substring%20with%20Concatenation%20of%20All%20Words.html 代码 代码语言:javascript 代码运行次数:0 代码运行 classSolution(object):deffindSubstring(self,s,words):""":...
S 仅由小写英文字母组成。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string python # 1047.删除所有相邻的重复字符 class Solution: def removeDuplicates(self,s: str) -> str: """ 借助辅助栈,同则出栈,否则入栈,最后拼接字符返回,时间O(n), 空间最...
LeetCode 442 Find All Duplicates in an Array (思维) Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice i...442. Find All Duplicates in an Array 与289. Game of Life一题...
输入:s = "cbaebabacd", p = "abc"输出:[0,6]解释:起始索引等于 0 的子串是 "cba", 它是 "abc" 的异位词。 起始索引等于 6 的子串是 "bac", 它是 "abc" 的异位词。 示例2: 输入:s = "abab", p = "ab"输出:[0,1,2]解释:起始索引等于 0 的子串是 "ab", 它是 "ab" 的异位词。
https://leetcode.com/problems/substring-with-concatenation-of-all-words/ 题意分析: 输入一个字符串s和一连串的长度相同的字符串数组words,找出仅由所有的words组成的s的子字符串起始位置。 题目思路: 由于给定的words的长度是相同的,题目难度就降低了很多。题目难度就在于判断一个字符串是否仅由words构成。这里...
[leetcode]Python实现-242.有效的字母异位词 242.有效的字母异位词 描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词。 示例 输入: s = “anagram”, t = “nagaram” 输出: true 输入: s = “rat”, t = “car” 输出: false 说明: 你可以假设字符串只......
LeetCode R.I.P. to my old Leetcode repository, where there were 5.7k+ stars and 2.2k+ forks (ever the top 3 in the field). Since free questions may be even mistakenly taken down by some companies, only solutions will be post on now. There are new LeetCode questions every week. I...
题目地址:https://leetcode-cn.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/ 题目描述 n 座城市,从 0 到 n-1 编号,其间共有 n-1 条路线。因此,要想在两座不同城市之间旅行只有唯一一条路线可供选择...
题目地址:https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/ Total Accepted: 14302 Total Submissions: 24993 Difficulty: Easy 题目描述 Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot...