Skip to content

Latest commit

 

History

History
36 lines (30 loc) · 734 Bytes

2335.装满杯子需要的最短总时长.md

File metadata and controls

36 lines (30 loc) · 734 Bytes

2335.装满杯子需要的最短总时长

/*
 * @lc app=leetcode.cn id=2335 lang=typescript
 *
 * [2335] 装满杯子需要的最短总时长
 */

// @lc code=start
function fillCups(amount: number[]): number {}
// @lc code=end

解法 1: 数学

function fillCups(amount: number[]): number {
  amount.sort((a, b) => a - b)
  const [a, b, c] = amount
  if (a + b >= c) return Math.ceil((a + b + c) / 2)
  return c
}

Case

test.each([
  { input: { amount: [1, 4, 2] }, output: 4 },
  { input: { amount: [5, 4, 4] }, output: 7 },
  { input: { amount: [5, 0, 0] }, output: 5 },
])('input: amount = $input.amount', ({ input: { amount }, output }) => {
  expect(fillCups(amount)).toEqual(output)
})