Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 671 Bytes

553.最优除法.md

File metadata and controls

34 lines (27 loc) · 671 Bytes

553.最优除法

/*
 * @lc app=leetcode.cn id=553 lang=typescript
 *
 * [553] 最优除法
 */

// @lc code=start
function optimalDivision(nums: number[]): string {}

// @lc code=end

数学

function optimalDivision(nums: number[]): string {
  return nums.length > 2 ? `${nums[0]}/(${nums.slice(1).join('/')})` : nums.join('/')
}

Case

test.each([
  { input: { nums: [1000, 100, 10, 2] }, output: '1000/(100/10/2)' },
  { input: { nums: [2, 3, 4] }, output: '2/(3/4)' },
  { input: { nums: [2] }, output: '2' },
])('input: nums = $input.nums', ({ input: { nums }, output }) => {
  expect(optimalDivision(nums)).toEqual(output)
})