题解 | #最大值#
最大值
http://www.nowcoder.com/practice/c0a95c1c30e94dc190e6acc42cb06930
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @param k int整型
* @return int整型
*/
public int maxValue (String s, int k) {
// write code here
if(k==s.length())return k;
int max=Integer.parseInt( s.substring(0,k));
//枚举起点 截取字符串比较 忘了Integer.parseInt方法
for(int i=k;i<s.length()-k;i++){
String sub=s.substring(i,i+k);
max=Math.max(max,Integer.parseInt(sub));
}
return max;
}
}