Compare Strings
来源:互联网 发布:淘宝联盟买家已收货 编辑:程序博客网 时间:2024/06/05 15:18
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 Caseletters.
ExampleFor A = "ABCD", B = "ABC", return true.
For A = "ABCD" B = "AABC", return false.
public boolean compareStrings(String A, String B) { if (A == null || B == null) { return false; } if (A.length() < B.length()) { return false; } if (A.length() >= 0 && B.length() == 0) { return true; } boolean[] visited = new boolean[A.length()]; for (int i = 0; i < visited.length; i++) { visited[i] = false; } int count = 0; for (int i = 0; i < B.length(); i++) { for (int j = 0; j < A.length(); j++) { if (B.charAt(i) == A.charAt(j) && !visited[j]) { count++; if (count == B.length()) { return true; } visited[j] = true; break; } } } return false; }思路:
O(n^2)遍历,consumable 用visited标志。
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
- raise函数
- Arale Base源码分析(含Attribute)
- USACO解题思路分析记录(Money System)
- hdu 2433 Travel 最短路 dijkstra算法。
- c结构体(待补充)
- Compare Strings
- Linux C编程一站式学习第九章
- viewDidApper,viewDidLoad
- 百度2012研发工程师笔试
- iOS开发工具——统计Crash的工具Crashlytics
- Python编程基础之十六多线程编程
- 数学之路-sas备忘(14)
- java 冒泡排序
- 单链表的基本操作(初始化,增加,删除)