본문 바로가기
python-algorithm

leetcode 2264. Largest 3-Same-Digit Number in String

by 무적김두칠 2023. 3. 7.

https://leetcode.com/problems/largest-3-same-digit-number-in-string/description/

 

Largest 3-Same-Digit Number in String - LeetCode

Can you solve this real interview question? Largest 3-Same-Digit Number in String - You are given a string num representing a large integer. An integer is good if it meets the following conditions: * It is a substring of num with length 3. * It consists of

leetcode.com

 

1
2
3
4
5
6
7
8
class Solution:
    def largestGoodInteger(self, num: str-> str:
        worst_case = ''
        for i in range(9-1-1):
            if str(i)*3 in num:
                return str(i)*3
        
        return worst_case
cs

문자열 첫 글자부터 한 글자씩 이동하면서 000, 111,222 인지 확인하는 방법도 있긴한데..
차라리 문자열 전체에 '999' -> '888'.. 있는지 확인하는게 더 직관적이라서 저렇게 풀었습니더

There is also a way to check whether it is 000, 111,222 by moving one character from the first character of the string.
Rather, it is more intuitive to check whether the entire string is '999' -> '888'..

반응형

댓글