leetcode每日一题2021.8.21-压缩字符串

LeetCode每日一题2021.8.21-压缩字符串

#class Solution {
public int putnum(char[] chars,int i,int num){//返回值是下次写入的坐标点
if(i>=chars.length || num<0){
return i;
}else{
int j=0;
if(num<10){
chars[i]=String.valueOf(num).charAt(0);
return i+1;
}else{
j=putnum(chars,i,num/10);
j=putnum(chars,j,num%10);
return j;
}
}
}
public int compress(char[] chars) {
if(chars.length<=1)
return chars.length;
char temp=‘a’;
if(chars[0]‘a’)
temp=‘b’;
int i=0;
int j=0;
int count=0;
while(i<chars.length){
if(chars[i]!=temp){//开始判断
if(count
0){
temp=chars[i];
i++;
count=1;
continue;
}else{
if(count1){
chars[j]=temp;
j++;
}else{
chars[j]=temp;
j=putnum(chars,j+1,count);
}
}
temp=chars[i];
count=1;
}else{
count++;
}
i++;
}
System.out.println(count);
System.out.println(j);
if(count
1){
chars[j]=temp;
return j+1;
} else{
chars[j]=temp;
j=putnum(chars,j+1,count);
}
return j;
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值