zoukankan      html  css  js  c++  java
  • lintcode702 连接两个字符串中的不同字符

    连接两个字符串中的不同字符 

     

    给出两个字符串, 你需要修改第一个字符串,将所有与第二个字符串中相同的字符删除, 并且第二个字符串中不同的字符与第一个字符串的不同字符连接

    思路:遍历两个字符串,找到互相不重复的字符

     1 class Solution {
     2 public:
     3     /*
     4      * @param : the 1st string
     5      * @param : the 2nd string
     6      * @return: uncommon characters of given strings
     7      */
     8     string concatenetedString(string &s1, string &s2) {
     9         // write your code here
    10         string res = "";
    11         for (int i = 0; i < s1.length(); i++) {
    12             if (s2.find(s1[i]) == string::npos) {
    13                 res = res + s1[i];
    14             }
    15         }
    16         for (int j = 0; j < s2.length(); j++) {
    17             if (s1.find(s2[j]) == string::npos) {
    18                 res = res + s2[j];
    19             }
    20         }
    21         return res;
    22     }
    23 };
  • 相关阅读:
    添加yum源
    tar命令
    tomcat压力测试、优化
    vi命令
    Linux简单命令
    Linux简单命令
    vi命令
    tomcat压力测试、优化
    tar命令
    动态加载 CSS 文件
  • 原文地址:https://www.cnblogs.com/gousheng/p/concatenetedString.html
Copyright © 2011-2022 走看看