題庫
上一題下一題
00:00

32. Candy

困難陣列AmazonGoogle

Give every child at least one candy while higher-rated adjacent children receive more. Return the minimum total.

範例 1:

輸入: ratings = [1,0,2]
輸出: 5

範例 2:

輸入: ratings = [1,2,2]
輸出: 4

限制條件:

  • 1 <= ratings.length <= 2 * 10^4
核心程式碼模式
● 已自動儲存第 1 行,第 1 欄