LintCode: Compare Strings

简介:

C++

复制代码
 1 class Solution {
 2 public:
 3     /**
 4      * @param A: A string includes Upper Case letters
 5      * @param B: A string includes Upper Case letter
 6      * @return:  if string A contains all of the characters in B return true 
 7      *           else return false
 8      */
 9     bool compareStrings(string A, string B) {
10         // write your code here
11         if (B == "") {
12             return true;
13         }
14         for (int i=0; i<B.size(); i++) {
15             int j = A.find_first_of(B[i]);
16             if (j == -1){
17                 return false;;
18             } else {
19                 A[j] = '-';
20             }
21         }
22         return true;
23     }
24 };
复制代码

 


本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/p/4999495.html,如需转载请自行联系原作者

相关文章
|
5月前
|
C++ 容器
POJ3096—Surprising Strings
POJ3096—Surprising Strings
|
C++
【PAT甲级 - C++题解】1040 Longest Symmetric String
【PAT甲级 - C++题解】1040 Longest Symmetric String
61 0
LeetCode 205. Isomorphic Strings
给定两个字符串 s 和 t,判断它们是否是同构的。 如果 s 中的字符可以被替换得到 t ,那么这两个字符串是同构的。 所有出现的字符都必须用另一个字符替换,同时保留字符的顺序。两个字符不能映射到同一个字符上,但字符可以映射自己本身。
68 0
LeetCode 205. Isomorphic Strings
LeetCode 415. Add Strings
给定两个字符串形式的非负整数 num1 和num2 ,计算它们的和。
90 0
LeetCode 415. Add Strings
|
机器学习/深度学习 人工智能
|
机器学习/深度学习