func nextBeautifulNumber(n int) int { for i := n + 1; ; i++ { if isBeautifulNumber(i) { return i } } return -1 }
func isBeautifulNumber(num int) bool { countMark := make([]int, 8) for num != 0 { div := num % 10 if div >= 8 || countMark[div] >= div { return false } countMark[div]++ num /= 10 } for i, count := range countMark { if count > 0 && count != i { return false } } return true }