标签:interview
http://lintcode.com/en/problem/compare-strings/
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) { // write your code here if (A == null || B == null) return false; Map<Character, Integer> map = new HashMap<>(); for (char c : A.toCharArray()) { Integer occurance = map.get(c); if (occurance == null) occurance = 0; occurance++; map.put(c, occurance); } for (char c : B.toCharArray()) { Integer occurance = map.get(c); if (occurance == null || occurance == 0) return false; occurance--; map.put(c, occurance); } return true; } }
标签:interview
原文地址:http://7371901.blog.51cto.com/7361901/1603953