Advertisement
sweet1cris

Untitled

Jan 9th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  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[] counts = new int[26];
  9.         for (int i = 0; i < 26; i++) {
  10.             counts[i] = 0;
  11.         }
  12.         for (int i = 0; i < A.length(); i++) {
  13.             counts[A.charAt(i) - 'A'] ++;
  14.         }
  15.         for (int i = 0; i < B.length(); i++) {
  16.             counts[B.charAt(i) - 'A'] --;
  17.             if (counts[B.charAt(i) - 'A'] < 0) {
  18.                 return false;
  19.             }
  20.         }
  21.         return true;
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement