手上有 n 朵花,每朵的花瓣数保存在一个数组中。我们每次可以选择任意一朵,拿走其中的一瓣或者两瓣,求掰完所有花的最少次数。
示例1
输入
[4,2,1]
输出
4
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @return int整型 */ public int petalsBreak (int[] petals) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型vector 花瓣数 * @return int整型 */ int petalsBreak(vector
& petals) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param petals int整型一维数组 花瓣数 # @return int整型 # class Solution: def petalsBreak(self , petals ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @return int整型 */ public int petalsBreak (List
petals) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @return int整型 */ function petalsBreak( petals ) { // write code here } module.exports = { petalsBreak : petalsBreak };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param petals int整型一维数组 花瓣数 # @return int整型 # class Solution: def petalsBreak(self , petals ): # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @return int整型 */ func petalsBreak( petals []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @param petalsLen int petals数组长度 * @return int整型 */ int petalsBreak(int* petals, int petalsLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param petals int整型一维数组 花瓣数 # @return int整型 # class Solution def petalsBreak(petals) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @return int整型 */ def petalsBreak(petals: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @return int整型 */ fun petalsBreak(petals: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @return int整型 */ public int petalsBreak (int[] petals) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @return int整型 */ export function petalsBreak(petals: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @return int整型 */ func petalsBreak ( _ petals: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param petals int整型一维数组 花瓣数 * @return int整型 */ pub fn petalsBreak(&self, petals: Vec
) -> i32 { // write code here } }
[4,2,1]
4