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. Loadrunner11.0 录制手机App脚本的方法一

    使用Loadrunner录制手机终端App脚本 1. 说明 目前手机APP上的功能日益丰富,对手机应用功能的性能测试需求也越来越多.公司比较抠门没有花钱买Loadrunner,可怜我们工作中一直用的破 ...

  2. linux:安装Memcache并使用

    1.Linux安装Memcache : curl -O http://memcached.org/files/memcached-1.5.4.tar.gz 解压 2.启动Memcache: memca ...

  3. python——mysql京东数据库设计案例(源码)

    # 显示界面信息# 循环界面信息# 根据用户输入数据来做相应的选择from pymysql import connect def jingdong_info(): '''#显示界面信息''' prin ...

  4. error: <item> inner element must either be a resource reference or empty.

    FAQ: Android resource compilation failedOutput: /home/cmm/code/AndroidHttpCapture/app/build/intermed ...

  5. GO语言标准库—命令行参数解析FLAG

    flag包是Go语言标准库提供用来解析命令行参数的包,使得开发命令行工具更为简单 常用方法 1.flag.Usage 输出使用方法,如linux下ls -h的帮助输出 2.flag.Type(参数名, ...

  6. java.lang.NullPointerException at java.lang.ProcessBuilder.start(Unknown Source) at org.apache.hadoop.util.Shell.runCommand(Shell.java:482)

    1:问题出现的原因,部署好的hadoop-2.6.4进行window10操作hadoop api出现的错误,具体错误是我向hdfs上传文件,还好点,之前解决过,这里不叙述,这里说一下从hdfs下载文件 ...

  7. 监控宝设置snmp

    https://wiki.jiankongbao.com/doku.php/%E6%96%87%E6%A1%A3:snmp%E8%AF%8A%E6%96%AD

  8. jQuery数字滚动(模拟网站人气、访问量递增)原创

    插件描述:实现数字上下滚动,模拟网站人气.访问量递增的动画效果,兼容性如下: 使用方法 $(el).runNum(val,params);   参数详解 val:数值型(默认70225800): pa ...

  9. [warn] 7#7: *676 a client request body is buffered to a temporary file /var/cache/nginx/client_temp/0000000007

    nginx 上传文件遇到的Bug. fastcgi_buffer_size 128k; fastcgi_buffers 8 128k; fastcgi_busy_buffers_size 128k; ...

  10. 【总结】瞬时高并发(秒杀/活动)Redis方案(转)

    转载地址:http://bradyzhu.iteye.com/blog/2270698 1,Redis 丰富的数据结构(Data Structures) 字符串(String) Redis字符串能包含 ...