leetcode/countKeyChanges.cpp

25 lines
512 B
C++
Raw Permalink Normal View History

2025-01-07 07:32:23 +00:00
#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;
}