Re: [閒聊] 每日leetcode

看板Marginalman作者 (是oin的說)時間1年前 (2024/08/16 10:08), 編輯推噓0(001)
留言1則, 1人參與, 1年前最新討論串724/1548 (看更多)
※ 引述 《DJYOMIYAHINA (通通打死)》 之銘言: :   :   : 真假 : 今天只有premium進得來喔 我以為大家都可以== : 我把題目貼上來 :   : 624. Maximum Distance in Arrays :   : You are given m arrays, where each array is sorted in ascending order. :   : You can pick up two integers from two different arrays (each array picks one) : and calculate the distance. We define the distance between two integers a and : b to be their absolute difference |a - b|. :   : Return the maximum distance. 官方好像蠻喜歡耍白痴的 題目翻譯 : 兩個不同的陣列 他們各拿一個元素最大的差是多少 思路 : 只要不要拿到當前的跟當前的比 就可以了 之前的min max可以沿用 這樣就可以比全部了 有沒有專精演算法物件導向的可愛小女孩要跟本姆咪深入交流(還有做愛) 如果沒有的話 我明天再問一次 ```cpp class Solution { public: int maxDistance(vector<vector<int>>& arrays) { int big = -999999; int bn = big; int small = 9999999; int sn = small; int res = 0; int n = arrays.size(); for(int i = 0 ; i < n ; i ++) { bn = arrays[i][arrays[i].size()-1]; res = max(res,bn-small); sn = arrays[i][0]; res = max(res,big-sn); small = min(sn,small); big = max(bn,big); } return res; } }; ``` -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.162.41.248 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1723774127.A.221.html

08/16 10:09, 1年前 , 1F
...
08/16 10:09, 1F
文章代碼(AID): #1clhIl8X (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1clhIl8X (Marginalman)