관리 메뉴

솜씨좋은장씨

[leetCode] 386. Lexicographical Numbers (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 386. Lexicographical Numbers (Python)

솜씨좋은장씨 2020. 7. 22. 22:37
728x90
반응형

Given an integer n, return 1 - n in lexicographical order.

For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].

Please optimize your algorithm to use less time and space. The input size may be as large as 5,000,000.

 

Solution

class Solution:
    def lexicalOrder(self, n: int) -> List[int]:
        my_nums = [str(i) for i in range(1, n+1)]
        
        my_nums = list(sorted(my_nums))
        
        return my_nums

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

 

Comments