利用字符重复出现的次数,编写一种方法,实现基本的字符串压缩功能。比如,字符串aabcccccaaa会变为a2bc5a3。 1.如果只有一个字符,1不用写 2.字符串中只包含大小写英文字母(a至z)。 数据范围: 050000 要求:时间复杂度O(N)
示例1
输入
"aabcccccaaa"
输出
"a2bc5a3"
示例2
输入
"shopeew"
输出
"shope2w"
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ public String compressString (String param) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ string compressString(string param) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param param string字符串 # @return string字符串 # class Solution: def compressString(self , param ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ public string compressString (string param) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ function compressString( param ) { // write code here } module.exports = { compressString : compressString };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param param string字符串 # @return string字符串 # class Solution: def compressString(self , param: str) -> str: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ func compressString( param string ) string { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ char* compressString(char* param ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param param string字符串 # @return string字符串 # class Solution def compressString(param) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ def compressString(param: String): String = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ fun compressString(param: String): String { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ public String compressString (String param) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ export function compressString(param: string): string { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ func compressString ( _ param: String) -> String { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param param string字符串 * @return string字符串 */ pub fn compressString(&self, param: String) -> String { // write code here } }
"aabcccccaaa"
"a2bc5a3"
"shopeew"
"shope2w"