#3019

Number of Changing Keys

newbie · 180 · lc easy +15 · verified · 80.5% accepted · 163 likes · top 92%

Description

You are given a 0-indexed string s typed by a user. A key change occurs when the letter typed differs from the previous letter, ignoring case (shift/caps lock are not counted as changes).

Return the number of key changes in s.

Note: typing 'a' then 'A' does not count as a key change.

Example 1:

Input: s = "aAbBcC"
Output: 2
Explanation:
From s[0] = 'a' to s[1] = 'A', there is no change of key as caps lock or shift is not counted.
From s[1] = 'A' to s[2] = 'b', there is a change of key.
From s[2] = 'b' to s[3] = 'B', there is no change of key as caps lock or shift is not counted.
From s[3] = 'B' to s[4] = 'c', there is a change of key.
From s[4] = 'c' to s[5] = 'C', there is no change of key as caps lock or shift is not counted.

Example 2:

Input: s = "AaAaAaaA"
Output: 0
Explanation: There is no change of key since only the letters 'a' and 'A' are pressed which does not require change of key.

Code

1
2
3