3463. Check If Digits Are Equal in String After Operations II Hard

@problem@discussion
#Math#String#Combinatorics#Number Theory



1/**
2 * [3463] Check If Digits Are Equal in String After Operations II
3 *
4 * You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits:
5 * 
6 * 	For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.
7 * 	Replace s with the sequence of newly calculated digits, maintaining the order in which they are computed.
8 * 
9 * Return true if the final two digits in s are the same; otherwise, return false.
10 *  
11 * <strong class="example">Example 1:
12 * <div class="example-block">
13 * Input: <span class="example-io">s = "3902"</span>
14 * Output: <span class="example-io">true</span>
15 * Explanation:
16 * 
17 * 	Initially, s = "3902"
18 * 	First operation:
19 * 	
20 * 		(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2
21 * 		(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9
22 * 		(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2
23 * 		s becomes "292"
24 * 	
25 * 	
26 * 	Second operation:
27 * 	
28 * 		(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1
29 * 		(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1
30 * 		s becomes "11"
31 * 	
32 * 	
33 * 	Since the digits in "11" are the same, the output is true.
34 * </div>
35 * <strong class="example">Example 2:
36 * <div class="example-block">
37 * Input: <span class="example-io">s = "34789"</span>
38 * Output: <span class="example-io">false</span>
39 * Explanation:
40 * 
41 * 	Initially, s = "34789".
42 * 	After the first operation, s = "7157".
43 * 	After the second operation, s = "862".
44 * 	After the third operation, s = "48".
45 * 	Since '4' != '8', the output is false.
46 * </div>
47 *  
48 * Constraints:
49 * 
50 * 	3 <= s.length <= 10^5
51 * 	s consists of only digits.
52 * 
53 */
54pub struct Solution {}
55
56// problem: https://leetcode.com/problems/check-if-digits-are-equal-in-string-after-operations-ii/
57// discuss: https://leetcode.com/problems/check-if-digits-are-equal-in-string-after-operations-ii/discuss/?currentPage=1&orderBy=most_votes&query=
58
59// submission codes start here
60
61impl Solution {
62    pub fn has_same_digits(s: String) -> bool {
63        false
64    }
65}
66
67// submission codes end
68
69#[cfg(test)]
70mod tests {
71    use super::*;
72
73    #[test]
74    fn test_3463() {
75    }
76}
77

Back
© 2026 bowen.ge All Rights Reserved.