作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 循环 日期 题目地址:https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/ 题目描述 We are given that the string "abc" is valid. From any valid string V, we may spli…
题目如下: We are given that the string "abc" is valid. From any valid string V, we may split V into two pieces X and Y such that X + Y (X concatenated with Y) is equal to V.  (X or Y may be empty.)  Then, X + "abc" + Y is also valid. If fo…
网址:https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/ 参考:https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/discuss/247626/JavaPythonC%2B%2B-Stack-Solution-O(N 方法1:使用c++自带的find函数和erase函数 class Solution { p…
We are given that the string "abc" is valid. From any valid string V, we may split V into two pieces X and Y such that X + Y (X concatenated with Y) is equal to V.  (Xor Y may be empty.)  Then, X + "abc" + Y is also valid. If for examp…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 二分查找 日期 题目地址:https://leetcode-cn.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array/ 题目描述 Given an array nums sorted in non-decreasing order, and a number t…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/shortest-completing-word/description/ 题目描述 Find the minimum length word from a given dictionary words, which has all the letters from the…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则+统计 日期 题目地址:https://leetcode.com/problems/most-common-word/description/ 题目描述 Given a paragraph and a list of banned words, return the most frequent word that is not in the li…
题目简述 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word is defined as a character sequence consists of non-spac…
[ 问题: ] Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. 给你一个字符串,设法获取它最后一个单词的长度.假设这个单词不存在,则返回0. [ 分析 : ] A word is defined…
题目如下: You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane. Example 1: Input: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]] Ou…
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case letters. If no such two words exist, return 0. Example…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BFS DFS 日期 题目地址:https://leetcode.com/problems/check-completeness-of-a-binary-tree/ 题目描述 Given a binary tree, determine if it is a complete binary tree. Definition of a complete…
题目: 输入字符串 s,返回其最后一个单词的长度 如 s="Hello World"   返回5 s="Hello World    "   返回5 s="  "     返回0 开始从前向后判断,超时了.改成从后向前判断,通过了. class Solution { public: int lengthOfLastWord(const char *s) { ; int slen = strlen(s); ; i >= ; i--) { if…
题目如下: Given an array nums of positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the array by any possible subset…
题目如下: Given a binary tree, determine if it is a complete binary tree. Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as fa…
题目如下: Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a…
We are given that the string "abc" is valid. From any valid string V, we may split V into two pieces X and Y such that X + Y (X concatenated with Y) is equal to V.  (X or Y may be empty.)  Then, X + "abc" + Y is also valid. If for exam…
[LeetCode]Longest Word in Dictionary through Deleting 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/longest-word-in-dictionary-through-deleting/#/description 题目描述: Given a string and a string dictionary, find the longest string in the di…
链接:https://leetcode.com/tag/design/ [146]LRU Cache [155]Min Stack [170]Two Sum III - Data structure design (2018年12月6日,周四) Design and implement a TwoSum class. It should support the following operations: add and find. add - Add the number to an inter…
目录 二分查找 排序的写法 BFS的写法 DFS的写法 回溯法 树 递归 迭代 前序遍历 中序遍历 后序遍历 构建完全二叉树 并查集 前缀树 图遍历 Dijkstra算法 Floyd-Warshall算法 Bellman-Ford算法 最小生成树 Kruskal算法 Prim算法 拓扑排序 双指针 动态规划 状态搜索 贪心 本文的目的是收集一些典型的题目,记住其写法,理解其思想,即可做到一通百通.欢迎大家提出宝贵意见! 博主有算法题解的微信公众号啦,欢迎关注「负雪明烛」,持续更新算法题的解题思路…
Algorithm [leetcode]557. Reverse Words in a String III https://leetcode.com/problems/reverse-words-in-a-string-iii/ 1)problem Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace…
[600] Non-negative Integers without Consecutive Ones [629] K Inverse Pairs Array [638] Shopping Offers [639] Decode Ways II [646] Maximum Length of Pair Chain [647] Palindromic Substrings 给定一个字符串,判断有多少子串是 palindromic 的,子串就算所有字母都相同,但是开始和结束位置的下标不同,也算不同…
[78]Subsets 给了一个 distinct 的数组,返回它所有的子集. Example: Input: nums = [,,] Output: [ [], [], [], [,,], [,], [,], [,], [] ] 题解:我是直接dfs(backtracking)了,有个小地方写错了(dfs那里),至少调整了十多分钟,下次不要写错了. class Solution { public: vector<vector<int>> subsets(vector<int…
[208]Implement Trie (Prefix Tree) (2018年11月27日) 实现基本的 trie 树,包括 insert, search, startWith 操作等 api. 题解:<程序员代码面试指南>chp5, 最后一题. 里面讲了怎么实现.这个就看代码吧.没啥好说的了. class Trie { public: /** Initialize your data structure here. */ Trie() { root = new TrieNode(); }…
[3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring (2019年1月22日,复习) [6]ZigZag Conversion (2019年1月22日,复习) [8]String to Integer (atoi) (2019年1月22日,复习) [10]Regular Expression Matching (2019年1月22日,复习) [12]In…
[LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/number-of-matching-subsequences/description/ 题目描述: Given string S and a dictionary of words words,…
[LeetCode]436. Find Right Interval 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/find-right-interval/description/ 题目描述: Given a set of intervals, for each of the interval i,…
[LeetCode]880. Decoded String at Index 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/decoded-string-at-index/description/ 题目描述: An encoded string S is given. To find and wri…
[LeetCode]833. Find And Replace in String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/find-and-replace-in-string/description/ 题目描述: To some string S, we will perform some…
[LeetCode]392. Is Subsequence 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/is-subsequence/description/ 题目描述: Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters…