注意到对于 的每一位数字 ,只需要每个好数中间的 个中的第 位为 ,其他的好数的这一位为 就好了,所以答案就是每一位的最大值。
#include <bits/stdc++.h>
using namespace std ;
string s ;
int maxn ;
int main() {
cin >> s ;
for(char c : s) {
maxn = max(maxn , int(c - '0')) ;
}
cout << maxn ;
return 0 ;
}
设 为字符串 的长度。
- 时间复杂度:。
- 空间复杂度:。
- 难度:上位红。
暂无评论