static boolean permutation(String s, String t){
if(s.length() != t.length()) return false;
int [] letters = new int [128];
char[] s_array = s.toCharArray();
for (char c: s_array){
letters[c]++;
}
for(int i = 0; i< t.length(); i++){
int c = (int) t.charAt(i);
letters[c]--;
if ( letters [c] < 0 )return false;
}
return true;
}
这个代码片段来自 Cracking the Coding Interview,我想知道字母 [c]++ 和字母 [c]-- 是什么意思。
这和字母[c++]一样吗?
最佳答案
So this code snippet is from Cracking the Coding Interview and I was wondering what the letters[c]++ and letters[c]-- means.
Is that the same thing as letters[c++]?
没有。 letters[c]++
相当于
letters[c] = letters[c] + 1;
和字母[c]--
执行
letters[c] = letters[c] - 1;
而letters[c++]
相当于,
letters[c] = letters[c];
c = c + 1;
关于java - 数组自增语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34966280/