题解 | #最大值#
最大值
https://www.nowcoder.com/practice/c0a95c1c30e94dc190e6acc42cb06930
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param k int整型 * @return int整型 */ public int maxValue (String s, int k) { // write code here if(s.length() == 0) { return 0; } // 当k等于字符串的长度时,最大值则为字符串本身 if(s.length() == k) { return Integer.parseInt(s); } // 最正整数 int max = 0; for(int i = 0; i < s.length() - k; i ++) { Integer val = Integer.parseInt(s.substring(i, i + k)); max = Math.max(max, val); } return max; } }