(String) 压缩String
e.g. aaabbcccc 返回a3b2c4
public static String compressString(String str) {
StringBuilder sb=new StringBuilder();
int count=1;
for(int i=0;i<str.length();i++) {
if((i!=str.length()-1) && str.charAt(i)==str.charAt(i+1))
count++;
else {
sb.append(str.charAt(i)+(count+""));
count=1;
}
}
return((sb.length()<str.length())? sb.toString(): str);
}
(String) 压缩String的更多相关文章
- [CareerCup] 1.5 Compress String 压缩字符串
1.5 Implement a method to perform basic string compression using the counts of repeated characters. ...
- String压缩 解压缩
数据传输时,有时需要将数据压缩和解压缩,本例使用GZIPOutputStream/GZIPInputStream实现. 1.使用ISO-8859-1作为中介编码,可以保证准确还原数据 2.字符编码确定 ...
- zstd c++ string 压缩&解压
zstd 简介 维基百科定义: Zstandard(或Zstd)是由Facebook的Yann Collet开发的一个无损数据压缩算法.该名称也指其C语言的参考实现.第1版的实现于2016年8月31日 ...
- .Net 中的 string、String、StringBuffer 内存处理性能 和 应用场景
body { font-family: Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif } code { color: ...
- [C#] string 与 String,大 S 与小 S 之间没有什么不可言说的秘密
string 与 String,大 S 与小 S 之间没有什么不可言说的秘密 目录 小写 string 与大写 String 声明与初始化 string string 的不可变性 正则 string ...
- java.lang.String.getBytes(String charsetName)方法实例
java.lang.String.getBytes(String charsetName) 方法编码将此String使用指定的字符集的字节序列,并将结果存储到一个新的字节数组. 声明 以下是java. ...
- Lua的string和string库总结
Lua有7种数据类型,分别是nil.boolean.number.string.table.function.userdata.这里我总结一下Lua的string类型和string库,复习一下,以便加 ...
- C#,int转成string,string转成int
转载:http://www.cnblogs.com/xshy3412/archive/2007/08/29/874362.html 1,int转成string用toString 或者Convert.t ...
- C#中对string与string[]的初步操作
开篇之作,简单的对string与string[]进行初步操作,入门篇也,不多说,直接上代码. using System; using System.Collections.Generic; using ...
随机推荐
- Shannon entropy
Shannon entropy is one of the most important metrics in information theory. Entropy measures the unc ...
- Leetcode 58 Length of Last Word 难度:0
https://leetcode.com/problems/length-of-last-word/ int lengthOfLastWord(char* s) { int ans = 0; int ...
- c#用牛顿法计算根号下2的值
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- RSS
RSS的基本概念 什么是RSS,RSS是在线共享内容的一种简易方式(也叫聚合内容,Really Simple Syndication).网站提供RSS输出有利于让用户获取网站内容的最新更新.用户可以使 ...
- iOS学习之内存管理
1.1 引用计数 Reference Count 1.2 自动引用计数,ARC(Automatic Reference Counting) 1引用计数 引用计数(Reference Count)是一个 ...
- css&js实现顶部banner滚动提示效果
以一个小例子来展示滚动提示的代码部分: try.html <div id="scrollobj" > <span class="scrollTxt&qu ...
- ssh连接linux服务器只显示-bash-4.1#不显示路径解决方法
ssh连接linux服务器只显示-bash-4.1#不显示路径时,我们只需要修改 ~/.bash_profile文件,如果不存在这个文件,那么新建一个,增加内容 export PS1='[\u@\ ...
- TCP/IP 协议:链路层概述
我们以一个常见的查看IP指令为出发点(ifconfig -a): 1.链路层是什么 链路层是指硬件层协议.也即网络所使用的硬件,比如:以太网(后文主要讨论对象),令牌环网,FDDI已经RS-232 ...
- Java初学者入门应该掌握的30个概念
1.OOP中唯一关系的是对象的接口是什么,就像计算机的销售商她不管电源内部结构 是怎样的,他只关系能否给你提供电就行了,也就是只要知道can or not而不是how and why.所有的程序是由一 ...
- uget和aria2
http://blog.csdn.net/luojiming1990/article/details/9078447 其中的aria2 -v要改成aria2c -v