Re: [閒聊] 每日LeetCode

看板Marginalman作者 (leaf)時間2年前 (2023/12/10 17:13), 編輯推噓2(202)
留言4則, 4人參與, 2年前最新討論串571/719 (看更多)
867. Transpose Matrix https://leetcode.com/problems/transpose-matrix/description/ 給定一個二維矩陣, 傳回欄列對調的結果(轉置矩陣) -- 還挺簡單, Python甚至可以一行解 最近怎麼都簡單題= = -- Python Code: class Solution: def transpose(self, matrix: List[List[int]]) -> List[List[int]]: m, n = len(matrix), len(matrix[0]) return [[matrix[j][i] for j in range(m)] for i in range(n)] C++ Code: class Solution { public: vector<vector<int>> transpose(vector<vector<int>>& matrix) { int m = matrix.size(); int n = matrix[0].size(); vector<vector<int>> ans(n, vector<int>(m, 0)); for (int i = 0;i < n;i++){ for (int j = 0;j < m;j++){ ans[i][j] = matrix[j][i]; } } return ans; } }; -- 咖啡是一種豆漿, 茶是一種蔬菜湯。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.161.65.130 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1702199613.A.3D0.html

12/10 17:13, 2年前 , 1F
這個月都easy
12/10 17:13, 1F

12/10 17:14, 2年前 , 2F
easy周
12/10 17:14, 2F

12/10 17:16, 2年前 , 3F
米板板主怎麼出現在這
12/10 17:16, 3F

12/10 17:56, 2年前 , 4F
我只是來打code的
12/10 17:56, 4F
文章代碼(AID): #1bTO4zFG (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1bTO4zFG (Marginalman)