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 };
时间: 2024-10-11 21:32:59

LintCode: Compare Strings的相关文章

[lintcode easy]Compare Strings

Compare Strings Compare two strings A and B, determine whether A contains all of the characters in B. The characters in string A and B are all Upper Case letters. Example For A = "ABCD", B = "ACD", return true. For A = "ABCD"

lintcode 容易题:Compare Strings 比较字符串

题目: 比较字符串 比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是 大写字母 样例 给出 A = "ABCD" B = "ACD",返回 true 给出 A = "ABCD" B = "AABC", 返回 false 注意 在 A 中出现的 B 字符串里的字符不需要连续或者有序. 解题: 用数组,或者用HashMap都可以,由于char String转换成Integer不是很熟悉,搞了好久...

Lintcode55 Compare Strings solution 题解

[题目描述] Compare two strings A and B, determine whether A contains all of the characters in B.The characters in string A and B are all Upper Case letters. Notice:The characters of B in A are not necessary continuous or ordered. 比较两个字符串A和B,确定A中是否包含B中所有的

Compare Strings

Compare two strings A and B, determine whether A contains all of the characters in B. The characters in string A and B are all Upper Case letters. Notice The characters of B in A are not necessary continuous or ordered. Example For A = "ABCD", B

LintCode Two Strings Are Anagrams

1. 把string变为char数组 2. 排序Arrays.sort() public class Solution { /** * @param s: The first string * @param b: The second string * @return true or false */ public boolean anagram(String s, String t) { if(s == null || t == null) return false; if(s.length(

LeetCode.1170-比较字符串中最小字符的出现频率(Compare Strings by Frequency of the Smallest Char)

这是小川的第412次更新,第444篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第263题(顺位题号是1170).在一个非空字符串s上定义一个函数f(s),该函数计算s中最小字符的出现频率.例如,如果s ="dcce",则f(s)= 2,因为最小字符为"c",其频率为2. 现在,给定字符串数组queries和words,返回一个整数数组answer, 其中每个answer[i]是使得f(queries[i]) < f(W)的单词数量,其

Hash function

Hash function From Wikipedia, the free encyclopedia A hash function that maps names to integers from 0 to 15. There is a collision between keys "John Smith" and "Sandra Dee". A hash function is any function that maps data of arbitrary

MYSQL INNODB主键使用varchar和int有什么区别?

本文和大家分享的主要是MYSQL 数据库主键使用varchar和int的区别,一起来看看吧,希望对大家学习mysql有所帮助. 我现在总结的3个问题: 1.tablespace中空间浪费 当然我们知道使用varchar可能会导致辅助索引比较大,因为用到varchar可能存储的字符较多,同时 在行头也存在一个可变字段字符区域(1-2)字节 而辅助索引叶子结点毕竟都存储了主键值,这样至少会多varchar数据字节数量+1(或者2) 字节- 4(int)字节空间. 如果辅助索引比较多空间浪费是可想而知

_cs, _ci, or _bin,

High Performance MySQL, Third Edition by Baron Schwartz, Peter Zaitsev, and Vadim Tkachenko http://dev.mysql.com/doc/refman/5.7/en/charset-general.html 1 DROP TABLE IF EXISTS `w_ci_bin_cs`; 2 CREATE TABLE `w_ci_bin_cs` ( 3 `pkey` int(11) NOT NULL AUT