55-比较字符串

来源:互联网 发布:人工智能哪个技术 编辑:程序博客网 时间:2024/06/05 17:43

4.20

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(B == ""){            return true;        }        if(A == ""){            return false;        }        int cA = A.length();        int cB = B.length();        if(cA < cB){            return false;        }        int i = 0;        for(i = 0;i < cB;i++){            if(A.contains(Character.toString(B.charAt(i)))){                A=A.replaceFirst(Character.toString(B.charAt(i)),"");            }            else{                return false;            }        }        if(i == cB){            return true;        }        else{            return false;        }            }}


0 0
原创粉丝点击