Compare Strings
来源:互联网 发布:手机优先网络列表设置 编辑:程序博客网 时间:2024/06/02 08:02
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.
Have you met this question in a real interview? Yes
Example
For A = “ABCD”, B = “ACD”, return true.
For A = “ABCD”, B = “AABC”, return false.
Note
The characters of B in A are not necessary continuous or ordered.
public class Solution { /** * @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 */ public boolean compareStrings(String A, String B) { if(A.length() < B.length()) return false; Map<Character, Integer> map = new HashMap<Character, Integer>(); for(int i = 0; i < A.length(); i++) { char c = A.charAt(i); if(map.containsKey(c)) { int value = map.get(c); map.put(c, ++value); }else { map.put(c, 1); } } for(int i = 0; i < B.length(); i++) { char c = B.charAt(i); if(map.containsKey(c)) { int value = map.get(c); if(--value < 0) return false; map.put(c, value); }else { return false; } } return true; }}
0 0
- Compare Strings
- Compare Strings
- Compare strings in java
- Case ignore compare strings
- #55 Compare Strings
- [Amazon] Two Strings Are Anagrams (Compare Strings)
- Compare javascript strings with
- strcmp, stricmp — compare strings.
- 【LintCode】 Compare Strings 比较字符串
- Lintcode55 Compare Strings solution 题解
- [LintCode]Compare Strings(C++|Python)
- How to compare Strings in Java
- lintcode 比较字符串(Compare Strings ) (Java)
- How to compare two strings with Linq to Entity
- How do I compare strings in Java?(Stackoverflow)
- 55.Compare Strings-比较字符串(容易题)
- compare
- compare
- JDBC工具类小结
- 【7】XML
- Redis高可用部署及监控
- 【8】Dom4j和XPath
- 正则表达式
- Compare Strings
- Swift中的if语句使用where
- (转帖)SQL Server处理四亿三千万记录大型项目实录
- JSON使用JsonIgnoreAttribute,ErrorHandlingAttribute,DefaultValueAttribute
- USACO--Friday the Thirteenth
- 使用PohtoView出现java.lang.IllegalArgumentException: pointerIndex out of range
- Android Studio 快捷键
- sublime There are no packages available for installation错误
- 客户端提交内容的HTML内容过滤根据