Re: [閒聊] 每日leetcode

看板Marginalman作者 (是oin的說)時間1年前 (2024/09/16 15:42), 編輯推噓1(100)
留言1則, 1人參與, 1年前最新討論串867/1554 (看更多)
題目 給你一堆時間 找最小的時間差距 思路 記錄後sort 遍歷一次 比對相鄰時間之間的差距 回傳最小的 ```cpp class Solution { public: int htom(string k) { int res = stoi(k.substr(3,2)); res += stoi(k.substr(0,2)) * 60; return res; } int findMinDifference(vector<string>& timePoints) { vector<int> save; int n = timePoints.size(); for(string k : timePoints) { save.push_back(htom(k)); } sort(save.begin() , save.end()); int res = abs(save[n-1] - 1440 - save[0] ); for(int i = 1 ; i < n ; i ++) { res = min(res , abs(save[i] - save[i-1])); } return res; } }; ``` -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.162.18.209 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1726472534.A.A7B.html

09/16 16:25, 1年前 , 1F
大師
09/16 16:25, 1F
文章代碼(AID): #1cv-5Mfx (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cv-5Mfx (Marginalman)