Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (みけねこ的鼻屎)時間2年前 (2023/06/19 21:12), 2年前編輯推噓2(203)
留言5則, 3人參與, 2年前最新討論串351/719 (看更多)
https://leetcode.com/problems/find-the-highest-altitude/description/ 1732. Find the Highest Altitude 有一個自行車手從高度為0的位置開始騎車,他要經過 n 個點,每個點的海拔 距離上個點為 gain[i],求出他騎到終點後最高海拔是多少。 Example 1: Input: gain = [-5,1,5,0,-7] Output: 1 Explanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1. Example 2: Input: gain = [-4,-3,-2,-1,4,3,2] Output: 0 Explanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0. 思路: 1.從0開始不斷計算新的點的海拔高度,並更新最大值。 Java Code: ---------------------------------------- class Solution { public int largestAltitude(int[] gain) { int res = 0; int height = 0; for (int h : gain) { height += h; res = Math.max(res, height); } return res; } } ---------------------------------------- 我這輩子只寫得出easy了 紫鯊 -- https://i.imgur.com/PIoxddO.jpg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.100.75.86 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1687180328.A.827.html

06/19 21:12, 2年前 , 1F
大師
06/19 21:12, 1F

06/19 21:12, 2年前 , 2F
你不是都hard起手
06/19 21:12, 2F

06/19 21:13, 2年前 , 3F
我hard題數只有20 對不起
06/19 21:13, 3F

06/20 09:40, 2年前 , 4F
你應該嘗試開始刷hard?感覺medium的題目對你已經沒難
06/20 09:40, 4F

06/20 09:40, 2年前 , 5F
度了
06/20 09:40, 5F
※ 編輯: Rushia (122.100.75.86 臺灣), 06/21/2023 00:32:19
文章代碼(AID): #1aa5GeWd (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1aa5GeWd (Marginalman)