zoukankan      html  css  js  c++  java
  • 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.

    int数组统计字符出现次数

     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[] AA = new int[26];
     9         int[] BB = new int[26];
    10         for (int i=0; i<A.length(); i++) {
    11             AA[A.charAt(i) - 'A']++;
    12         }
    13         for (int i=0; i<B.length(); i++) {
    14             BB[B.charAt(i) - 'A']++;
    15             if (BB[B.charAt(i) - 'A'] > AA[B.charAt(i) - 'A']) return false;
    16         }
    17         return true;
    18     }
    19 }
  • 相关阅读:
    gcc相关
    test
    第二次课
    VS快捷键
    第7章 站在对象模型的尖端
    第6章 执行期语意学
    第5章 构造, 析构, 拷贝语意学
    第4章 Function语意学
    第一次课
    第3章 Data语意学
  • 原文地址:https://www.cnblogs.com/EdwardLiu/p/4273817.html
Copyright © 2011-2022 走看看