2346. Largest 3-Same-Digit Number in String
My accepted Python solution to LeetCode problem 2346, Largest 3-Same-Digit Number in String, running in 3ms.
- Difficulty: Easy
- Python
- Runtime 3ms
- Memory 17.1MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 3ms, memory 17.1MB, accepted 2025-12-29.
class Solution:
def largestGoodInteger(self, num: str) -> str:
# Find largest 3-digit substring with same digits
# Time: O(n), Space: O(1)
result = ""
for i in range(len(num) - 2):
if num[i] == num[i+1] == num[i+2]:
if num[i:i+3] > result:
result = num[i:i+3]
return result