LeetCode Weekly Contest 26】的更多相关文章

[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ [题意] 让你把一段序列去掉3个元素,然后分成4个部分; 要求这4个部分的和相同; 问你可不可能; [题解] 先枚举要删除的3个元素中的中间那个元素j; 然后把整个序列分成左边和右边两个部分; 然后再左边的序列中枚举i; 然后把0..j-1分成0..i-1和i+1..j-1两个部分; 然后看这两个部…
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/friend-circles/ [题意] 告诉你任意两个人是不是朋友. 问你最后有多少个连通块; [题解] 裸并查集. [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #d…
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence-ii/ [题意] 字符串变成多个了; (不止两个) 让你求最长不公共子序列 [题解] 因为最大长度为10; 所以把每个长度有哪些字符串记录下来; 然后从字符串长度由大到小枚举len; 假设这个答案序列为len长度的某个字符串; 然后看看len长度的字符串有没有和它一样的字符串(即出现两次及以上)…
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence-i/ [题意] 让你求两个字符串的最长不公共子序列的长度; 即这个序列是两个字符串中的一个的子序列; 同时要求这个序列不是所有其他任意一个字符串的子序列; [题解] 两个字符串相同就无解; 否则输出两个字符串的长度中较大者; [完整代码] #include <bits/stdc++.h> usi…
写的有点晚了. 我每次都是先看一下这里http://bookshadow.com/leetcode/的思路,然后再开始写我自己的. 1. 521. Longest Uncommon Subsequence I 说实话,看完就懵逼了,这怎么做,难道是dp,后仔细一想,不对啊,很简单啊. 只要2个字符串不相等,返回长度较长的那个就行了. 刚开始,考虑,如果其中之一为空串,我返回的-1,不知道怎么想的.这显然是错的. class Solution { public: int findLUSlength…
LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 Total Submissions: 1844 Difficulty: Easy Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. Note: The…
leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round. class Solution { public: string predictPartyVictory(string senate) { int len = senate.size(); int r = 0; int d = 0; int i = 0; while(1) { if(senate[…
LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them.…
Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个由整数组成的 N × N 矩阵,其中有多少个 3 × 3 的 “幻方” 子矩阵?(每个子矩阵都是连续的). 直接模拟即可,本来是签到题,由于粗心,浪费了时间. class Solution { public: int numMagicSquaresInside(vector<vector<int&…
链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash加查找 class Solution { public: int findLHS(vector<int>& nums) { if (nums.empty()) ; ; int len = nums.size(); unordered_map<int, int> hash(len…