Leetcode Note: Go - Check if Numbers Are Ascending in a Sentence

Check if Numbers Are Ascending in a Sentence - LeetCode
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/

  • Go 言語で取り組んだメモ

回答

Check if Numbers Are Ascending in a Sentence - LeetCode
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/solutions/1526111/go-clean-and-optimized-alternatives/

func areNumbersAscending(s string) bool {
	parts := strings.Split(s, " ")
	prev := -1
	for _, part := range parts {
		if n, err := strconv.Atoi(part); err == nil {
			if n <= prev {
				return false
			}
			prev = n
		}
	}
	return true
}