3019. Number of Changing Keys ¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8 9 10class Solution { public: int countKeyChanges(string s) { int ans = 0; for (int i = 1; i < s.length(); ++i) if (tolower(s[i]) != tolower(s[i - 1])) ++ans; return ans; } }; 1 2 3 4 5 6 7 8 9class Solution { public int countKeyChanges(String s) { int ans = 0; for (int i = 1; i < s.length(); ++i) if (Character.toLowerCase(s.charAt(i)) != Character.toLowerCase(s.charAt(i - 1))) ++ans; return ans; } } 1 2 3 4class Solution: def countKeyChanges(self, s: str) -> int: return sum(a.lower() != b.lower() for a, b in itertools.pairwise(s))