首页 > 代码库 > LintCode-Compare Strings
LintCode-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 = "ABC", return true.
For A = "ABCD" B = "AABC", return false.
Solution:
1 public class Solution { 2 /** 3 * @param A : A string includes Upper Case letters 4 * @param B : A string includes Upper Case letter 5 * @return : if string A contains all of the characters in B return true else return false 6 */ 7 public boolean compareStrings(String A, String B) { 8 int[] record = new int[256]; 9 Arrays.fill(record,0);10 for (int i=0;i<A.length();i++){11 int ind = (int) A.charAt(i);12 record[ind]++;13 }14 15 for (int i=0;i<B.length();i++){16 int ind = (int) B.charAt(i);17 if (record[ind]==0) return false;18 else record[ind]--;19 }20 21 return true;22 }23 }
LintCode-Compare Strings
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。