农场主有一群牛,每头牛都有一个编号。编号由小写字母组成。现在农场主想要将这群牛划分成尽可能多的片段,同一编号的牛最多出现在一个片段中。请你实现一个函数,返回一个表示每个牛群片段的长度的列表。
示例1
输入
"ababcbacadefegdeihijhklij"
输出
[9,7,9]
示例2
输入
"abcdabcdabcd"
输出
[12]
备注:
字符串长度范围为 [1, 500],s 仅由小写英文字母组成
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 */ public int[] partition_cows (String s) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型vector */ vector
partition_cows(string s) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @return int整型一维数组 # class Solution: def partition_cows(self , s ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 */ public List
partition_cows (string s) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 */ function partition_cows( s ) { // write code here } module.exports = { partition_cows : partition_cows };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @return int整型一维数组 # class Solution: def partition_cows(self , s: str) -> List[int]: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 */ func partition_cows( s string ) []int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 * @return int* returnSize 返回数组行数 */ int* partition_cows(char* s, int* returnSize ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @return int整型一维数组 # class Solution def partition_cows(s) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 */ def partition_cows(s: String): Array[Int] = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 */ fun partition_cows(s: String): IntArray { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 */ public int[] partition_cows (String s) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 */ export function partition_cows(s: string): number[] { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 */ func partition_cows ( _ s: String) -> [Int] { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型一维数组 */ pub fn partition_cows(&self, s: String) -> Vec
{ // write code here } }
"ababcbacadefegdeihijhklij"
[9,7,9]
"abcdabcdabcd"
[12]