[LintCode]Compare Strings(C++|Python)
来源:互联网 发布:淘宝劳模代购 编辑:程序博客网 时间:2024/05/19 01:07
C++ Version:
class Solution {public: /** * @param A: A string includes Upper Case letters * @param B: A string includes Upper Case letter * @return: if string A contains all of the characters in B return true * else return false */ bool compareStrings(string A, string B) { // write your code here int count[2][26] = {0}; for (int i = 0; i < A.length(); i++) { count[0][A[i] - 'A']++; } for (int i = 0; i < B.length(); i++) { count[1][B[i] - 'A']++; } for (int i = 0; i < 26; i++) { if (count[0][i] < count[1][i]) { return false; } } return true; }};
Python Version:
class Solution: """ @param A : A string includes Upper Case letters @param B : A string includes Upper Case letters @return : if string A contains all of the characters in B return True else return False """ def compareStrings(self, A, B): # write your code here a = list(A) b = list(B) for c in b: if c not in a: return False a.remove(c) return True
阅读全文
0 0
- [LintCode]Compare Strings(C++|Python)
- 【LintCode】 Compare Strings 比较字符串
- lintcode 比较字符串(Compare Strings ) (Java)
- [LintCode]Two Strings Are Anagrams(C++|Java|Python)
- Compare Strings
- Compare Strings
- Compare strings in java
- Case ignore compare strings
- #55 Compare Strings
- LintCode python 小白-简单题-638-Strings Homomorphism
- [Amazon] Two Strings Are Anagrams (Compare Strings)
- lintcode(638)Strings Homomorphism
- LintCode之Strings Homomorphism
- Compare javascript strings with
- strcmp, stricmp — compare strings.
- Lintcode55 Compare Strings solution 题解
- c++compare
- 【leetcode】205. Isomorphic Strings(Python & C++)
- Stockbroker Grapevine (弗洛伊德)
- POJ 2421 Constructing Roads
- 练习 2-2 在不使用运算符&&或||的条件下编写一个与上面的for 循环语句等价的循环语句。
- 51nod 1212 模板
- Pandas学习之文本拆分
- [LintCode]Compare Strings(C++|Python)
- Spring相关部分注解的用法:
- spark 调度模块详解及源码分析
- C++OJ提交题目中的语言选项里G++与C++的区别
- js数组去重
- jquery中的attr()和prop()的区别
- PAT---1021. 个位数统计 (15)
- 1、在一个由自然数1-1000中某些数字所组成的数组中,每个数字可能出现零次或者多次。设计一个算法,找出出现次数最多的数字。
- 解决Failed to load class "org.slf4j.impl.StaticLoggerBinder"