Leetcode Problem 2264. Largest 3-Same-Digit Number in String

2264. Largest 3-Same-Digit Number in String

Leetcode Solutions

Single Iteration Approach

  1. Initialize maxDigit to the NUL character \0.
  2. Iterate over num from index 0 to len(num) - 3.
    • For each index i, check if num[i], num[i + 1], and num[i + 2] are the same.
    • If they are the same, update maxDigit to the maximum of maxDigit and num[i].
  3. After the iteration, check if maxDigit is still the NUL character.
    • If it is, return an empty string.
    • Otherwise, return a string composed of three maxDigit characters.
UML Thumbnail

Multiple Iterations for Each Digit

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...