problem 1078. Occurrences After Bigram 题意 solution: class Solution { public: vector<string> findOcurrences(string text, string first, string second) { string bigram = first + ' ' + second + ' '; vector<string> res; int n = bigram.size(); auto…
题目如下: Given words first and second, consider occurrences in some text of the form "first second third", where second comes immediately after first, and third comes immediately after second. For each such occurrence, add "third" to the…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串分割遍历 日期 题目地址:https://leetcode.com/problems/occurrences-after-bigram/ 题目描述 Given words first and second, consider occurrences in some text of the form "first second third&quo…
lc1078 Occurrences After Bigram trim().split()将原字符串转换成words数组 依次匹配first和second,若两者都能匹配上,则下一个单词为third,将其加入List<String> res 返回 res.toArray(new String[0]) class Solution { public String[] findOcurrences(String text, String first, String second) { Strin…
这道题目是典型的DFS+记忆化搜索, DP思想.符合:含重叠子问题,无后效性等特点. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 105 int dp[MAXN][MAXN]; int a[MAXN][MAXN]; int n, k; int max(int a, int b) { return a>b ? a:b; } int dfs(int x, int y) { i…
题意:给定两个串s和t,多次询问s的一个区间[l ,r]中有多少个子串与t串相同 len<=1e3,q<=1e5 思路:前缀和 #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<iostream> #include<algorithm> #include<map> #include<set> #i…
problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完…
problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binary Numbers; 完…
problem 1025. Divisor Game 参考 1. Leetcode_easy_1025. Divisor Game; 完…
problem 1029. Two City Scheduling 参考 1. Leetcode_easy_1029. Two City Scheduling; 完…
problem 1030. Matrix Cells in Distance Order 参考 1. Leetcode_easy_1030. Matrix Cells in Distance Order; 完…
problem 1033. Moving Stones Until Consecutive 参考 1. Leetcode_easy_1033. Moving Stones Until Consecutive; 完…
problem 1037. Valid Boomerang 参考 1. Leetcode_easy_1037. Valid Boomerang; 完…
problem 1042. Flower Planting With No Adjacent 参考 1. Leetcode_easy_1042. Flower Planting With No Adjacent; 完…
problem 1046. Last Stone Weight 参考 1. Leetcode_easy_1046. Last Stone Weight; 完…
problem 1047. Remove All Adjacent Duplicates In String 参考 1. Leetcode_easy_1047. Remove All Adjacent Duplicates In String; 完…
problem 1051. Height Checker solution class Solution { public: int heightChecker(vector<int>& heights) { vector<int> orders = heights; sort(orders.begin(), orders.end()); ; ; i<heights.size(); i++) { if(heights[i]!=orders[i]) res++; } r…
problem 1071. Greatest Common Divisor of Strings solution class Solution { public: string gcdOfStrings(string str1, string str2) { return (str1+str2==str2+str1) ? (str1.substr(, gcd(str1.size(), str2.size()))) : ""; } }; 参考 1. Leetcode_easy_1071…
problem 1154. Day of the Year solution class Solution { public: int dayOfYear(string date) { // 平年 闰年 ] = {, , , , , , , , , , , }; , )), m = stoi(date.substr(, )), d = stoi(date.substr()); && y % == && (y % != || y % == )) d++;//leap year…
problem 1170. Compare Strings by Frequency of the Smallest Character 参考 1. Leetcode_easy_1170. Compare Strings by Frequency of the Smallest Character; 完…
problem 1160. Find Words That Can Be Formed by Characters solution class Solution { public: int countCharacters(vector<string>& words, string chars) { ; unordered_map<char, int> charmap; for(auto ch:chars) charmap[ch]++; for(auto word:word…
problem 997. Find the Town Judge solution: class Solution { public: int findJudge(int N, vector<vector<int>>& trust) { vector<); ]]--; balance[t[]]++; } ; i<=N; i++) { ) return i; } ; } }; 参考 1. Leetcode_easy_997. Find the Town Judge…
problem 994. Rotting Oranges 参考 1. Leetcode_easy_994. Rotting Oranges; 完…
problem 993. Cousins in Binary Tree 参考 1. Leetcode_easy_993. Cousins in Binary Tree; 完…
problem 989. Add to Array-Form of Integer 参考 1. Leetcode_easy_989. Add to Array-Form of Integer; 完…
problem 985. Sum of Even Numbers After Queries class Solution { public: vector<int> sumEvenAfterQueries(vector<int>& A, vector<vector<int>>& queries) { vector<int> res; ; ==) sum +=a; for(auto query:queries) { ]]%== )…
problem 977. Squares of a Sorted Array solution: class Solution { public: vector<int> sortedSquares(vector<int>& A) { for(auto &a:A) a *=a; sort(A.begin(), A.end()); return A; } }; 参考1. Leetcode_easy_977. Squares of a Sorted Array; 完…
problem 976. Largest Perimeter Triangle solution: class Solution { public: int largestPerimeter(vector<int>& A) { sort(A.begin(), A.end());//decrease. ; i>; i--) { ]+A[i-]) ]+A[i-]; } ; } }; 参考 1. Leetcode_easy_976. Largest Perimeter Triangle…
problem 970. Powerful Integers solution: class Solution { public: vector<int> powerfulIntegers(int x, int y, int bound) { unordered_set<int> tmp; ; a<bound; a*=x)// { ; a+b<=bound; b*=y) { tmp.insert(a+b);// ) break;// } ) break; } retur…
problem 965. Univalued Binary Tree 参考 1. Leetcode_easy_965. Univalued Binary Tree; 完…