581. Shortest Unsorted Continuous Subarray

Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.

You need to find the shortest such subarray and output its length.

Input: [2, 6, 4, 8, 10, 9, 15]
Output: 5
Explanation: You need to sort [6, 4, 8, 10, 9] in ascending order to make the whole array sorted in ascending order.

排好序,然后对比一下就行了

 class Solution {
public:
int findUnsortedSubarray(vector<int>& nums) {
int n=nums.size();
vector<int> nums2;
nums2.insert(nums2.end(),nums.begin(),nums.end());
sort(nums2.begin(),nums2.end());
int st=,ed=n-;
while(st!=n&&nums2[st]==nums[st]) st++;
while(ed!=-&&nums2[ed]==nums[ed]) ed--;
if(st==n) return ;
return ed-st+;
} };

582. Kill Process

删除一个树上的节点,求出所有子节点编号

真的很生疏了,树都不知道怎么遍历了

由于可能编号开的很大,因此用map作下映射,不说数据范围真坑,一直TLE(leetcode有TLE?),最后改了下数组大小AC了

Input:
pid = [1, 3, 10, 5]
ppid = [3, 0, 5, 3]
kill = 5
Output: [5,10]
Explanation:
3
/ \
1 5
/
10
Kill 5 will also kill 10.
 class Solution {
public:
vector<int> ans;
map<int,int> mp;
map<int,int> fmp;
int tot;
vector<int> g[];
void dfs(int i){
ans.push_back(fmp[i]);
for(int j=;j<g[i].size();j++){
dfs(g[i][j]);
}
}
vector<int> killProcess(vector<int>& pid, vector<int>& ppid, int kill) {
int n=pid.size();
int i,st;
tot=;
for(i=;i<n;i++){
if(!mp[ppid[i]]){
mp[ppid[i]]=tot;
fmp[tot]=ppid[i];
tot++;
}
if(!mp[pid[i]]){
mp[pid[i]]=tot;
fmp[tot]=pid[i];
tot++;
}
int u=mp[ppid[i]],v=mp[pid[i]];
g[u].push_back(v);
}
dfs(mp[kill]);
return ans; }
};

583. Delete Operation for Two Strings

Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either string.

Input: "sea", "eat"
Output: 2
Explanation: You need one step to make "sea" to "ea" and another step to make "eat" to "ea".

求下最长公共序列,注意是序列不是子串,因为对于abcab,abab这样的情况,公共子串就无法解决,求完之后减一下就可以了

 class Solution {
public:
int Max(int a,int b)
{
return (a>b)?a:b;
}
int creatDp(string s1,string s2,int *dp)
{
int len1 = s1.length();
int len2 = s2.length();
//int *dp = new int[len1*len2];
//先求出第一行
for(int j = ;j<len2;j++)
{
if(s1[] == s2[j]){
*(dp+*len2+j) = ;
for(;j<len2;j++)
*(dp+*len2+j) = ;
break;
}
else
*(dp+*len2+j) = ;
}
//然后求第一列
for(int i = ;i<len1;i++)
{
if(s1[i] == s2[]){
*(dp+i*len2+) = ;
for(;i<len1;i++)
*(dp+i*len2+) = ;
break;
}
else
*(dp+i*len2+) = ;
}
//求其他的数据
for(int i =;i<len1;i++)
{
for(int j =;j<len2;j++)
{
if(s1[i] == s2[j])
*(dp+i*len2+j) = *(dp+(i-)*len2+(j-))+;
else
*(dp+i*len2+j) = Max(*(dp+(i-)*len2+j),*(dp+i*len2+j-));
}
}
return dp[len1*len2-];
}
int minDistance(string word1, string word2) {
int len1 = word1.length();
int len2 = word2.length();
int *dp = new int[len1*len2];
int w=creatDp(word1, word2,dp);
return len1-w+len2-w;
}
};

587. Erect the Fence

裸凸包问题,找了几个模板都没套进去,重载操作符没法用,23333,leetcode真坑

LeetCode Weekly Contest 32的更多相关文章

  1. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  2. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

  3. LeetCode Weekly Contest 23

    LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...

  4. Leetcode Weekly Contest 86

    Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个 ...

  5. LeetCode Weekly Contest

    链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...

  6. 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ ...

  7. 【LeetCode Weekly Contest 26 Q3】Friend Circles

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/friend-circles/ [题意] 告诉你任意两个 ...

  8. 【LeetCode Weekly Contest 26 Q2】Longest Uncommon Subsequence II

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence ...

  9. 【LeetCode Weekly Contest 26 Q1】Longest Uncommon Subsequence I

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence ...

随机推荐

  1. shell 批量替换内容

    一.查找/data/www/vhosts/WOStest2_YiiFramework/console/sh/下所有.sh文件 把/data/www/vhosts/WOS_YiiFramework 替换 ...

  2. 学习REST

    REST:Representational State Transfer,资源的表现状态转换.可以理解为对资源的操作.   1. 资源 资源就是业务对象,如图片.文本.歌曲或者客户.交易等.这些是用户 ...

  3. 步步为营-78-新闻展示(Ajax+Json+easyUI)

    Json:JavaScript Object Notation 1.1 Json对象的接收处理 <!DOCTYPE html> <html xmlns="http://ww ...

  4. linux基础练习题(2)

    Linux命令作业(关卡二) 练习题1 理解操作系统的作用,以及各种操作系统的不同 要求: 为什么要有OS?没有OS能行吗?原因是什么? Linux内核指的是什么? Linux主要应用在哪些地方? 使 ...

  5. Elasticsearch和HDFS 容错机制 备忘

    1.Elasticsearch 横向扩容以及容错机制http://www.bubuko.com/infodetail-2499254.html 2.HDFS容错机制详解https://www.cnbl ...

  6. 【转】利用 selenium 的 webdrive 驱动 headless chrome

    1.参考 使用 headless chrome进行测试 2.概念 Headless模式解决了什么问题: 自动化工具例如 selenium 利用有头浏览器进行测试,面临效率和稳定性的影响,所以出现了 H ...

  7. Crystal Reports报表使用 [一]

    1.Crystal Reports 是什么? Crystal Reports 是一个功能强大.动态和可操作的报表解决方案,它将帮助你通过网络设计.开发.可视化及发布报表,或嵌入到企业应用之中.有了它, ...

  8. Codechef FIBTREE 树链剖分 主席树 LCA 二次剩余 快速幂

    原文链接https://www.cnblogs.com/zhouzhendong/p/CC-FIBTREE.html 题目传送门 - CC-FIBTREE 题意 给定一个有 $n$ 个节点,初始点权都 ...

  9. day 57 jQuery插件

    在jQuery的console里面 '321'+8  输出结果是"3218"  直接作为字符串给拼接上了 如果是"321"-8 输出结果就是313 直接转换成数 ...

  10. Manager解决Process进程之间的数据访问

    import multiprocessing mgr = mutiprocessing.Manager() 开启一个守护子进程,并返回用来与其通信的管理器 share_list = mgr.list( ...