본문 바로가기
python-algorithm

leetcode 2042. Check if Numbers Are Ascending in a Sentence

by 무적김두칠 2023. 1. 13.

https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/description/

 

Check if Numbers Are Ascending in a Sentence - LeetCode

Check if Numbers Are Ascending in a Sentence - A sentence is a list of tokens separated by a single space with no leading or trailing spaces. Every token is either a positive number consisting of digits 0-9 with no leading zeros, or a word consisting of lo

leetcode.com

 

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
    def areNumbersAscending(self, s: str-> bool:
        nums = []
        for i in s.split():
            if i.isdigit():
                nums.append(int(i))
        answer = True
        for i in range(1len(nums)):
            if nums[i - 1>= nums[i]:
                answer = False
                return answer
        return answer
 
cs

크게 어려운 문제는 아니였는데 line6에서 type casting 해주셔야합니다!!

It wasn't a very difficult problem, but you have to type cast on line6!!

반응형

댓글