討論串[閒聊] 每日LeetCode
共 719 篇文章
內容預覽:
解1 TLE. class Solution:. def rangeBitwiseAnd(self, left: int, right: int) -> int:. res = left. for i in range(left, right + 1):. res &= i. return res.
(還有1032個字)
內容預覽:
https://leetcode.com/problems/find-the-town-judge/. 997. Find the Town Judge. 小鎮上有n個人被標記為1到n,傳言其中有1個人是鎮法官. 如果鎮法官存在:. 1. 鎮法官不相信任何人. 2. 除了鎮法官以外的每個人都信任鎮法
(還有780個字)
內容預覽:
easy submit了四次才對. 我這輩子就這樣了. 嗚嗚哇哇哇. 997. Find the Town Judge. class Solution {. public:. int findJudge(int n, vector<vector<int>>& trust) {. vector<int
(還有192個字)
內容預覽:
1245. Tree Diameter. premium題 找出一個tree的最長path. 看起來不太直覺 其實只是實作一個找depth的function. 同時記下前兩深的subtree的深度 同時更新最長path長度. 最長path必會是某個root的兩個最深subtree的深度相加再+2.
(還有892個字)
內容預覽:
787. Cheapest Flights Within K Stops. 有n個city,要從src飛到dst、k代表你能轉機幾次. 給一個array flights裡面有三個元素[from, to, price]. 代表飛機的起點、終點以及價錢. 請問你最少要花多少錢才能從src到dst. 思路
(還有1813個字)