赎金信
public static boolean method(String smallStr,String bigStr){
int[] start = new int[26];
for (char small : smallStr.toCharArray()) {
int index = bigStr.indexOf(small,start[small-'a']);
if (index == -1) {
return false;
}
start[small-'a'] = index+1;
}
return true;
}
字符串的单词数
public static int method1(String s) {
String trim = s.trim();
if (trim.equals("")) {
return 0;
}
String[] s1 = trim.split("\\s+");
return s1.length;
}
public static int method2(String s) {
int n = s.length();
int count = 0;
for (int i = 0; i < n; i++) {
if ( (i == 0||s.charAt(i-1) == ' ') && s.charAt(i) != ' ') {
count++;
}
}
return count;
}