利用字符重复出现的次数,实现字符串压缩功能。若“压缩”后的字符串没有变短,则返回原先的字符串。你可以假设字符串中只包含大小写英文字母(a至z)
示例1
输入
"abcccaaaa"
输出
"a1b1c3a4"
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ public String compressString (String test_string) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ string compressString(string test_string) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param test_string string字符串 输入参数 # @return string字符串 # class Solution: def compressString(self , test_string ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ public string compressString (string test_string) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ function compressString( test_string ) { // write code here } module.exports = { compressString : compressString };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param test_string string字符串 输入参数 # @return string字符串 # class Solution: def compressString(self , test_string ): # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ func compressString( test_string string ) string { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ char* compressString(char* test_string ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param test_string string字符串 输入参数 # @return string字符串 # class Solution def compressString(test_string) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ def compressString(test_string: String): String = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ fun compressString(test_string: String): String { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ public String compressString (String test_string) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ export function compressString(test_string: string): string { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ func compressString ( _ test_string: String) -> String { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param test_string string字符串 输入参数 * @return string字符串 */ pub fn compressString(&self, test_string: String) -> String { // write code here } }
"abcccaaaa"
"a1b1c3a4"