一个由小写字母组成的字符串可以看成一些同一字母的最大碎片组成的。例如,"aaabbaaac"是由下面碎片组成的:'aaa','bb','c'。现在给定一个字符串,请你帮助计算这个字符串的所有碎片的平均长度是多少,结果直接取整,无需保留小数
示例1
输入
"aaabbaaac"
输出
2
说明
所有碎片的平均长度= (3 + 2 + 3 + 1) / 4 = 2
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ public int GetFragment (String str) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ int GetFragment(string str) { // write code here } };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param str string字符串 # @return int整型 # class Solution: def GetFragment(self , str ): # write code here
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ function GetFragment( str ) { // write code here } module.exports = { GetFragment : GetFragment };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param str string字符串 # @return int整型 # class Solution: def GetFragment(self , str ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ func GetFragment( str string ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ int GetFragment(char* str ) { // write code here }
"aaabbaaac"
2