zoukankan      html  css  js  c++  java
  • lintcode: Missing String

    Missing String 

     描述:

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

    Example

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

    Return ["This", "an"]

    代码

     1 class Solution {
     2 public:
     3     /*
     4      * @param : a given string
     5      * @param : another given string
     6      * @return: An array of missing string
     7      */
     8     vector<string> missingString(string str1, string str2) {
     9         // Write your code here
    10         vector<string> vec1;
    11         vector<string> vec2;
    12         vector<string> res;
    13         
    14         string buf;
    15         stringstream ss1(str1); //字符流
    16         while (ss1 >> buf) {
    17             vec1.push_back(buf);
    18         }
    19         
    20         stringstream ss2(str2);
    21         while (ss2 >> buf) {
    22             vec2.push_back(buf);
    23         }
    24         
    25 
    26         for (int i = 0; i < vec1.size(); i++) {
    27             vector<string>::iterator it;
    28             it = find(vec2.begin(), vec2.end(), vec1[i]);
    29             if (it == vec2.end()) {
    30                 res.push_back(vec1[i]);
    31             }
    32         }
    33         return res;
    34     }
    35 };
  • 相关阅读:
    CODE[VS] 2506 可恶的体育老师
    CODE[VS] 3411 洪水
    CODE[VS] 2692 小明过生日
    CODE[VS] 2291 糖果堆
    CODE[VS] 2008 你已经爱我多久了
    忽然之间
    Amazing grace 奇异恩典
    无处安放
    AC日记
    AC日记
  • 原文地址:https://www.cnblogs.com/gousheng/p/7595212.html
Copyright © 2011-2022 走看看