All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g2801_2900.s2860_happy_students.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.32
Show newest version
package g2801_2900.s2860_happy_students

// #Medium #Array #Sorting #Enumeration #2023_12_21_Time_512_ms_(100.00%)_Space_56.2_MB_(50.00%)

import java.util.Collections

class Solution {
    fun countWays(nums: List): Int {
        Collections.sort(nums)
        var cnt = 0
        val n = nums.size
        if (nums[0] != 0) {
            cnt++
        }
        for (i in 0 until n - 1) {
            if (nums[i] < (i + 1) && (nums[i + 1] > (i + 1))) {
                cnt++
            }
        }
        if (n > nums[n - 1]) {
            cnt++
        }
        return cnt
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy