File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 2132
2132
3014|[ Minimum Number of Pushes to Type Word I] ( ./solutions/3014-minimum-number-of-pushes-to-type-word-i.js ) |Easy|
2133
2133
3015|[ Count the Number of Houses at a Certain Distance I] ( ./solutions/3015-count-the-number-of-houses-at-a-certain-distance-i.js ) |Medium|
2134
2134
3016|[ Minimum Number of Pushes to Type Word II] ( ./solutions/3016-minimum-number-of-pushes-to-type-word-ii.js ) |Medium|
2135
+ 3019|[ Number of Changing Keys] ( ./solutions/3019-number-of-changing-keys.js ) |Easy|
2135
2136
3024|[ Type of Triangle] ( ./solutions/3024-type-of-triangle.js ) |Easy|
2136
2137
3042|[ Count Prefix and Suffix Pairs I] ( ./solutions/3042-count-prefix-and-suffix-pairs-i.js ) |Easy|
2137
2138
3066|[ Minimum Operations to Exceed Threshold Value II] ( ./solutions/3066-minimum-operations-to-exceed-threshold-value-ii.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 3019. Number of Changing Keys
3
+ * https://leetcode.com/problems/number-of-changing-keys/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given a 0-indexed string s typed by a user. Changing a key is defined as using a key
7
+ * different from the last used key. For example, s = "ab" has a change of a key while s = "bBBb"
8
+ * does not have any.
9
+ *
10
+ * Return the number of times the user had to change the key.
11
+ *
12
+ * Note: Modifiers like shift or caps lock won't be counted in changing the key that is if a user
13
+ * typed the letter 'a' and then the letter 'A' then it will not be considered as a changing of key.
14
+ */
15
+
16
+ /**
17
+ * @param {string } s
18
+ * @return {number }
19
+ */
20
+ var countKeyChanges = function ( s ) {
21
+ let result = 0 ;
22
+
23
+ for ( let i = 1 ; i < s . length ; i ++ ) {
24
+ if ( s [ i ] . toLowerCase ( ) !== s [ i - 1 ] . toLowerCase ( ) ) {
25
+ result ++ ;
26
+ }
27
+ }
28
+
29
+ return result ;
30
+ } ;
You can’t perform that action at this time.
0 commit comments