Skip to content

Commit 2bad572

Browse files
committedMar 10, 2025
Add solution #3461
1 parent 1a402e0 commit 2bad572

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@
842842
3397|[Maximum Number of Distinct Elements After Operations](./3397-maximum-number-of-distinct-elements-after-operations.js)|Medium|
843843
3402|[Minimum Operations to Make Columns Strictly Increasing](./3402-minimum-operations-to-make-columns-strictly-increasing.js)|Easy|
844844
3452|[Sum of Good Numbers](./3452-sum-of-good-numbers.js)|Easy|
845+
3461|[Check If Digits Are Equal in String After Operations I](./3461-check-if-digits-are-equal-in-string-after-operations-i.js)|Easy|
845846

846847
## License
847848

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* 3461. Check If Digits Are Equal in String After Operations I
3+
* https://leetcode.com/problems/check-if-digits-are-equal-in-string-after-operations-i/
4+
* Difficulty: Easy
5+
*
6+
* You are given a string s consisting of digits. Perform the following operation repeatedly
7+
* until the string has exactly two digits:
8+
* - For each pair of consecutive digits in s, starting from the first digit, calculate a new
9+
* digit as the sum of the two digits modulo 10.
10+
* - Replace s with the sequence of newly calculated digits, maintaining the order in which
11+
* they are computed.
12+
*
13+
* Return true if the final two digits in s are the same; otherwise, return false.
14+
*/
15+
16+
/**
17+
* @param {string} s
18+
* @return {boolean}
19+
*/
20+
var hasSameDigits = function(s) {
21+
while (s.length > 2) {
22+
let next = '';
23+
for (let i = 0; i < s.length - 1; i++) {
24+
next += (parseInt(s[i]) + parseInt(s[i + 1])) % 10;
25+
}
26+
s = next;
27+
}
28+
return s[0] === s[1];
29+
};

0 commit comments

Comments
 (0)
Please sign in to comment.