每日一题:按键变更的次数
This commit is contained in:
parent
6aeaa7fda6
commit
e4090f9a09
25
countKeyChanges.cpp
Normal file
25
countKeyChanges.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int countKeyChanges(string s) {
|
||||||
|
int toReturn = 0;
|
||||||
|
for(int i = 0; i< s.size()-1 ;i++){
|
||||||
|
if((s[i] == s[i+1]) or (s[i] == s[i+1] - 32) or (s[i] == s[i+1] + 32)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
toReturn++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
Solution s;
|
||||||
|
cout << s.countKeyChanges("aAbBcC") << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user