Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2fd6165

Browse files
committed
Add solution #3019
1 parent 860a9ce commit 2fd6165

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,7 @@
21322132
3014|[Minimum Number of Pushes to Type Word I](./solutions/3014-minimum-number-of-pushes-to-type-word-i.js)|Easy|
21332133
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|
21342134
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|
21352136
3024|[Type of Triangle](./solutions/3024-type-of-triangle.js)|Easy|
21362137
3042|[Count Prefix and Suffix Pairs I](./solutions/3042-count-prefix-and-suffix-pairs-i.js)|Easy|
21372138
3066|[Minimum Operations to Exceed Threshold Value II](./solutions/3066-minimum-operations-to-exceed-threshold-value-ii.js)|Medium|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
};

0 commit comments

Comments
 (0)