Missing String

 描述:

Given two strings, you have to find the missing string.

Have you met this question in a real interview?

Yes
Example

Given a string str1 = This is an example
Given another string str2 = is example

Return ["This", "an"]

代码

 class Solution {
public:
/*
* @param : a given string
* @param : another given string
* @return: An array of missing string
*/
vector<string> missingString(string str1, string str2) {
// Write your code here
vector<string> vec1;
vector<string> vec2;
vector<string> res; string buf;
stringstream ss1(str1); //字符流
while (ss1 >> buf) {
vec1.push_back(buf);
} stringstream ss2(str2);
while (ss2 >> buf) {
vec2.push_back(buf);
} for (int i = ; i < vec1.size(); i++) {
vector<string>::iterator it;
it = find(vec2.begin(), vec2.end(), vec1[i]);
if (it == vec2.end()) {
res.push_back(vec1[i]);
}
}
return res;
}
};

lintcode: Missing String的更多相关文章

  1. LintCode Interleaving String

    Given three strings: s1, s2, s3, determine whether s3 is formed by the interleaving of s1 and s2. Ex ...

  2. [LintCode] Scramble String 爬行字符串

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  3. Lintcode: Rotate String

    Given a string and an offset, rotate string by offset. (rotate from left to right) Example Given &qu ...

  4. ActiveX(三)ActiveX 调用 Js

    在上一篇随笔: ActiveX(二)Js 监听 ActiveX中的事件  中,已经可以实现 Js 监听 ActiveX中的事件,至此.Js 和 ActiveX 已经可以实现双向通讯了.但是.这样的实现 ...

  5. C#操作 word代码

    #region 读取word /// <summary> /// 读取word所有文字内容(不包含表格) /// </summary> /// <returns>w ...

  6. ASP.NET mvc异常处理的方法

    第一种:全局异常处理 1.首先常见保存异常的类(就是将异常信息写入到文件中去) public class LogManager { private string logFilePath = strin ...

  7. c#操作word表格

    http://www.webshu.net/jiaocheng/programme/ASPNET/200804/6499.html <% if request("infoid" ...

  8. DataGrid3

    a标签,DataGrid的数据绑定 1.function aa(id, url) {            //alert(id);            window.open(url + '&am ...

  9. DataGrid2

    1.DataGrid的button属性设置 CommandName="ToEdit": 对其中的button按钮进行选择: CommandArgument='<%#Eval( ...

随机推荐

  1. mysql 使用order by

    1.mysql 使用order by field() 自定义排序 order by field(value,str1,str2,str3,str4......strn) 例如:select * fro ...

  2. 【oracle笔记3】多表查询

    *多表查询 分类:1.合并结果集 2.连接查询 3.子查询 *合并结果集:要求被合并的表中,列的类型和列数相同. *UNION,去除重复行.完全相同的行会被去除 *UNION ALL:不去除重复行. ...

  3. python 输入一个整数,判断其是否既是3的倍数,又是5的倍数

    v = int(input('请输入一个整数:')) if v % 3 == 0 and v % 5 ==0: print(v,'即是3的倍数又是5的倍数') else: print('不是3或5的倍 ...

  4. chromium之lazy_instance

    先看看介绍 // The LazyInstance<Type, Traits> class manages a single instance of Type, // which will ...

  5. Java 8 – Map排序

    前提 Map是Java中最常用的集合类之一,这里整理了关于HashMap的排序 (关于List的排序,请查看Collections.sort()的doc或源码). 将无序的HashMap借助Strea ...

  6. table表单制作个人简历

    应用table表单,编程个人简历表单,同时运用了跨行rowspan和跨列colspan. <!DOCTYPE html> <html> <head> <met ...

  7. vi模式下的编辑、删除、保存和退出

    vi + 文件名:进入 vi 模式 编辑模式:shift+: 退出编辑模式:Esc 退出编辑模式后可进行光标的上下左右移动(偶尔会出现ABCD,还不知道怎么解决,目前只能出来一个删除一个) 光标处:按 ...

  8. 【Spark】源码分析之SparkContext

    一.概述 SaprkContext非常重要,是Spark提交任务到集群的入口 SparkContext中没有main方法,在SparkContext主构造器中,主要做一下四件事情: 1. 调用crea ...

  9. 微信小程序实现watch属性监听数据变化

    Vue 提供了一种通用的方式来观察和响应 Vue 实例上的数据变动:监听属性 watch. 虽然watch的滥用会导致性能不佳,但在一些情况下我们还是需要watch,使得代码更加简洁.逻辑更加清晰(其 ...

  10. php连接数据库(一)

    1.php链接数据库: 1.链接数据库 2.判断是否连接成功 3.设置字符集 4.选择数据库 5.准备SQL语句 6.发送SQL语句 7.处理结果集 8.释放资源(关闭数据库) $result = m ...