The code you provided has some syntax errors and is missing the main function. Here's a corrected version of your code:

fun main() {
    val n = readLine()!!.toInt()
    val s: List<Int> = readLine()!!.split(' ').map(String::toInt)
    var ans = 0
    var st = 0
    for (i in 0 until n) {
        if (i != 0 && s[i] != s[i - 1]) {
            if (st > ans) ans = st
            st = 1
        } else st++
    }
    if (st > ans) ans = st
    println(ans)
}

This code reads an integer n from the input and then reads a list of n integers. It then finds the longest consecutive subsequence in the list and prints its length

fun main val n=readLine!!toInt val sListInt=readLine!!split mapStringtoInt var ans=0 var st=0 fori in 0 until n ifi!=0&&si!=si-1 ifstans ans=st st=1

原文地址: http://www.cveoy.top/t/topic/ifGz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录