3019. Number of Changing Keys Easy
1/**
2 * [3019] Number of Changing Keys
3 *
4 * You are given a 0-indexed string s typed by a user. Changing a key is defined as using a key different from the last used key. For example, s = "ab" has a change of a key while s = "bBBb" does not have any.
5 * Return the number of times the user had to change the key.
6 * Note: Modifiers like shift or caps lock won't be counted in changing the key that is if a user typed the letter 'a' and then the letter 'A' then it will not be considered as a changing of key.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: s = "aAbBcC"
11 * Output: 2
12 * Explanation:
13 * From s[0] = 'a' to s[1] = 'A', there is no change of key as caps lock or shift is not counted.
14 * From s[1] = 'A' to s[2] = 'b', there is a change of key.
15 * From s[2] = 'b' to s[3] = 'B', there is no change of key as caps lock or shift is not counted.
16 * From s[3] = 'B' to s[4] = 'c', there is a change of key.
17 * From s[4] = 'c' to s[5] = 'C', there is no change of key as caps lock or shift is not counted.
18 *
19 * <strong class="example">Example 2:
20 *
21 * Input: s = "AaAaAaaA"
22 * Output: 0
23 * Explanation: There is no change of key since only the letters 'a' and 'A' are<!-- notionvc: 8849fe75-f31e-41dc-a2e0-b7d33d8427d2 --> pressed which does not require change of key.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= s.length <= 100
29 * s consists of only upper case and lower case English letters.
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/number-of-changing-keys/
35// discuss: https://leetcode.com/problems/number-of-changing-keys/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn count_key_changes(s: String) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_3019() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.