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. javascript实现jsonp跨域问题+原理

    在工作中往往存在跨域的问题 ,跨域是什么概念就不在这里了,搜这类问题的肯定已经知道了.下面直接探讨jsonp跨域原理 jspon跨域原理: 1.动态创建一个script标签 var script = ...

  2. 极光IM简单接入步骤

    最近生接触了一下android,尝试导入极光的demo到android study 各种错误,然后下载极光生成的项目也是各种错误,感觉好像有点脱离时代了,记得以前用eclipse写android只需要 ...

  3. Ajax,跨域,nrm

    一.ajax 原理 和 使用 ajax,即在不重新加载整个网页的情况下,对网页的某部分进行更新. 下面演示ajax 的实现原理 配置: cd ajax 参考:http://www.expressjs. ...

  4. ES6系列文章 异步神器async-await

    关于异步处理,ES5的回调使我们陷入地狱,ES6的Promise使我们脱离魔障,终于.ES7的async-await带我们走向光明.今天就来学习一下 async-await. async-await和 ...

  5. 【读书笔记】The Swift Programming Language (Swift 4.0.3)

    素材:Language Guide 初次接触 Swift,建议先看下 A Swift Tour,否则思维转换会很费力,容易卡死或钻牛角尖. 同样是每一章只总结3个自己认为最重要的点.这样挺好!强迫你去 ...

  6. iOS之NSDictionary初始化的坑

    最近在做项目的时候遇到一个挺坑的崩溃问题,是由于NSDictionary初始化时nil指针引起的崩溃.假设我们现在要初始化一个{key1 : value1, key2 : value2, key3 : ...

  7. java读取xml文件的四种方法

    Xml代码 <?xml version="1.0" encoding="GB2312"?> <RESULT> <VALUE> ...

  8. idea 引入多项目

    1.先导入总包 2.右侧mavenmaven,选择parent的pom.xml 3.右上角“Project Structure”检查SDK

  9. RPM包、YUM、system初始化进程基本知识

  10. redis安装make失败,make[1]: *** [adlist.o] Error 127....

    解压后 执行make后报错: cd src && make all make[1]: Entering directory `/home/liuchaofan/redis-3.0.7/ ...