Skip to content

Commit cc899fc

Browse files
committed
feat(leetcode): add No.3461
1 parent d418f24 commit cc899fc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// https://leetcode.com/problems/check-if-digits-are-equal-in-string-after-operations-i/description/
2+
// algorithms
3+
// Easy (79.8%)
4+
// Total Accepted: 38.7K
5+
// Total Submissions: 48.5K
6+
7+
8+
class Solution {
9+
10+
public boolean hasSameDigits(String s) {
11+
if (s.length() == 2) {
12+
return s.charAt(0) == s.charAt(1);
13+
}
14+
15+
StringBuilder sb = new StringBuilder();
16+
int len = s.length();
17+
for (int i = 0; i < len - 1; i++) {
18+
sb.append((s.charAt(i) - '0' + s.charAt(i + 1) - '0') % 10);
19+
}
20+
21+
return hasSameDigits(sb.toString());
22+
}
23+
24+
}
25+
26+

0 commit comments

Comments
 (0)