From e4090f9a09f9028c0d45b40f0f8d788dde4d1fed Mon Sep 17 00:00:00 2001 From: carry Date: Tue, 7 Jan 2025 15:32:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F=E6=97=A5=E4=B8=80=E9=A2=98=EF=BC=9A?= =?UTF-8?q?=E6=8C=89=E9=94=AE=E5=8F=98=E6=9B=B4=E7=9A=84=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- countKeyChanges.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 countKeyChanges.cpp diff --git a/countKeyChanges.cpp b/countKeyChanges.cpp new file mode 100644 index 0000000..ca5ac59 --- /dev/null +++ b/countKeyChanges.cpp @@ -0,0 +1,25 @@ +#include +#include +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; +} \ No newline at end of file