为什么内存超限了,求高手解答(附代码)

信念、 信念、 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
PAT上的一道题目,链接:https://www.patest.cn/contests/pat-b-practise/1084
代码如下,最后一个测试点过不去,说是内存超限


import java.util.Scanner;
public class Main{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int d;
int n;
d = in.nextInt();
n = in.nextInt();
String s = "" + d;
n = n - 1;
while(n>0){
s = change(s);
n--;
}
System.out.println(s);
in.close();
}
public static String change(String s){
String temp = "";
char ch;
int count;
int i=0;
while(i<s.length()){
ch = s.charAt(i++);
count = 1;
while(i<s.length()&&ch==s.charAt(i)){
count++;
i++;
}
temp += "" + ch + count;
}
return temp;
}
}求解答,万分感谢!
...全文
评论 7
收藏 已收藏
分享
返回顶部
信念、
Java SE 62,621 成员 307,251 内容