LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 3ms, memory 17.1MB, accepted 2025-12-29.

python
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

Source