Re: [閒聊] 每日leetcode

看板 Marginalman
作者 Rushia (早瀬ユウカの体操服 )
時間 2024-11-23 01:50:16
留言 1 ( 1推 0噓 0→ )
回文 60則
※ 引述《JIWP (神楽めあ的錢包)》之銘言: : 1072. Flip Columns For Maximum Number of Equal Rows : 有m*n的binary matrix : 可以選擇任一行,將那一行的元素翻轉(1->0、0->1) : 這個操作可以做任意次 : 請問經過任意次操作後 : 可以得到最多幾個列(列裡面的元素全為1或0) 一開始看hint根本看不懂在工三小 就用暴力法解 代碼很醜就不貼了 測資大小才300所以O(n^3)可以過 看了下解答區讚最多的思路 簡單來說一個列只可能是全0或全1 假設你翻轉了一個列為全0,所有和他長的一樣的列也會變全0 然後和他剛好完全相反的會變全1 0101 -> 翻轉成全0 -> 0000 0101 -> -> 0000 1010 -> 翻轉成全1 -> 1111 0011 -> 不全0或全1-> 1100 這兩個的數量加起來就是翻轉後的相等列,取最大就好 直接run只贏過50% 對列做字串hash跳過長的一樣的列 跑得跟我暴力法一樣慢(???) 最後改用標記法不hash就贏過99% 又學到一課 Java Code ---------------------------------------------------- class Solution { public int maxEqualRowsAfterFlips(int[][] matrix) { int ans = 0; int m = matrix.length; int n = matrix[0].length; boolean[] visited = new boolean[m]; for (int i = 0; i < m; i++) { if (visited[i]) { continue; } visited[i] = true; int[] flip = new int[n]; for (int j = 0; j < n; j++) { flip[j] = 1 - matrix[i][j]; } int cnt = 0; for (int j = i; j < m; j++) { if (Arrays.equals(matrix[j], matrix[i]) || Arrays.equals(matrix[j], flip)) { visited[j] = true; cnt++; } } ans = Math.max(ans, cnt); } return ans; } } ---------------------------------------------------- -- https://i.imgur.com/pD41PYS.jpeg
Re: [閒聊] 每日leetcode
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.158.191.3 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1732297819.A.C64.html

回文

[閒聊] 每日Leetcode
marginalman Rushia
2022-03-29 10:59:05
[閒聊] 每日LeetCode
1 3 marginalman Rushia
2022-09-14 23:02:29
Re: [閒聊] 每日LeetCode
1 3 marginalman Rushia
2022-09-15 12:15:47
Re: [閒聊] 每日LeetCode
2 2 marginalman pandix
2022-09-15 12:57:55
Re: [閒聊] 每日LeetCode
marginalman Rushia
2022-09-21 15:41:31
Re: [閒聊] 每日LeetCode
3 5 marginalman Rushia
2022-09-21 15:53:41
Re: [閒聊] 每日LeetCode
4 5 marginalman Rushia
2022-09-22 10:40:56
Re: [閒聊] 每日LeetCode
1 6 marginalman yam276
2022-09-22 11:38:13
Re: [閒聊] 每日LeetCode
1 2 marginalman yam276
2022-09-22 16:12:43
Re: [閒聊] 每日LeetCode
2 7 marginalman Rushia
2022-09-24 12:54:51
Re: [閒聊] 每日LeetCode
marginalman Rushia
2022-09-25 15:51:32
Re: [閒聊] 每日LeetCode
2 4 marginalman pandix
2022-09-26 19:55:34
Re: [閒聊] 每日LeetCode
marginalman pandix
2022-09-27 23:40:49
Re: [閒聊] 每日LeetCode
2 5 marginalman Rushia
2022-09-27 23:48:21
Re: [閒聊] 每日LeetCode
2 2 marginalman Rushia
2022-09-28 10:06:53
Re: [閒聊] 每日LeetCode
3 5 marginalman pandix
2022-09-28 19:00:24
Re: [閒聊] 每日LeetCode
4 5 marginalman Rushia
2022-09-29 10:22:39
Re: [閒聊] 每日LeetCode
3 6 marginalman pandix
2022-09-29 10:45:51
Re: [閒聊] 每日LeetCode
marginalman pandix
2022-09-29 23:33:27
Re: [閒聊] 每日LeetCode
3 3 marginalman Rushia
2022-10-01 15:21:10
Re: [閒聊] 每日LeetCode
2 3 marginalman pandix
2022-10-01 23:23:27
Re: [閒聊] 每日LeetCode
3 8 marginalman Pash97143
2022-10-02 00:38:24
Re: [閒聊] 每日LeetCode
2 2 marginalman fxfxxxfxx
2022-10-02 09:00:25
Re: [閒聊] 每日LeetCode
4 5 marginalman pandix
2022-10-02 17:01:46
Re: [閒聊] 每日LeetCode
5 7 marginalman fxfxxxfxx
2022-10-03 09:12:35
Re: [閒聊] 每日LeetCode
4 4 marginalman pandix
2022-10-03 09:37:14
Re: [閒聊] 每日LeetCode
marginalman qwer338859
2022-10-03 11:25:38
Re: [閒聊] 每日LeetCode
5 6 marginalman Rushia
2022-10-03 11:26:31
Re: [閒聊] 每日LeetCode
3 3 marginalman Rushia
2022-10-04 09:52:42
Re: [閒聊] 每日LeetCode
5 5 marginalman Rushia
2022-10-05 09:25:45
Re: [閒聊] 每日LeetCode
4 5 marginalman pandix
2022-10-05 09:40:08
Re: [閒聊] 每日LeetCode
4 6 marginalman Rushia
2022-10-06 10:18:27
Re: [閒聊] 每日LeetCode
marginalman pandix
2022-10-06 10:27:49
Re: [閒聊] 每日LeetCode
1 3 marginalman Rushia
2022-10-06 10:53:34
Re: [閒聊] 每日LeetCode
marginalman fxfxxxfxx
2022-10-06 15:02:54
Re: [閒聊] 每日LeetCode
2 5 marginalman pandix
2022-10-07 12:06:19
Re: [閒聊] 每日LeetCode
1 4 marginalman fxfxxxfxx
2022-10-07 19:36:15
Re: [閒聊] 每日LeetCode
3 3 marginalman Rushia
2022-10-08 12:37:47
Re: [閒聊] 每日LeetCode
marginalman pandix
2022-10-08 13:02:09
Re: [閒聊] 每日LeetCode
2 4 marginalman fxfxxxfxx
2022-10-08 14:13:09
Re: [閒聊] 每日LeetCode
1 1 marginalman SecondRun
2022-10-08 16:09:03
Re: [閒聊] 每日LeetCode
2 2 marginalman Rushia
2022-10-09 14:11:02
Re: [閒聊] 每日LeetCode
1 2 marginalman Rushia
2022-10-10 14:38:07
Re: [閒聊] 每日LeetCode
2 2 marginalman Rushia
2022-10-11 11:21:19
Re: [閒聊] 每日LeetCode
2 3 marginalman Rushia
2022-10-12 10:06:55
Re: [閒聊] 每日LeetCode
6 10 marginalman Rushia
2022-10-13 09:12:42
Re: [閒聊] 每日LeetCode
4 6 marginalman fxfxxxfxx
2022-10-13 12:17:26
Re: [閒聊] 每日LeetCode
6 7 marginalman Rushia
2022-10-14 16:24:57
Re: [閒聊] 每日LeetCode
3 3 marginalman pandix
2022-10-15 18:59:40
Re: [閒聊] 每日LeetCode
4 7 marginalman pandix
2022-10-16 16:24:59
Re: [閒聊] 每日LeetCode
2 2 marginalman Rushia
2022-10-17 09:42:50
Re: [閒聊] 每日LeetCode
2 3 marginalman abcd991276
2022-10-18 15:24:10
Re: [閒聊] 每日LeetCode
1 2 marginalman Rushia
2022-10-18 16:37:56
Re: [閒聊] 每日LeetCode
2 3 marginalman pandix
2022-10-18 16:50:13
Re: [閒聊] 每日LeetCode
marginalman Rushia
2022-10-19 09:45:48
Re: [閒聊] 每日LeetCode
1 3 marginalman pandix
2022-10-19 11:07:59
Re: [閒聊] 每日LeetCode
3 4 marginalman Rushia
2022-10-20 09:21:06
Re: [閒聊] 每日LeetCode
6 6 marginalman fxfxxxfxx
2022-10-21 02:46:22
Re: [閒聊] 每日LeetCode
1 2 marginalman Rushia
2022-10-21 09:12:55
Re: [閒聊] 每日LeetCode
3 4 marginalman pandix
2022-10-22 15:36:18

留言

※ 編輯: Rushia (49.158.191.3 臺灣), 11/23/2024 01:54:09
oin1104 大師 11/23 02:46 1F

最新文章

[日本] 日本各大網站代購
helpbuy b7753251
2024-11-23 07:36:29
[贈送] 一葉蓮小苗
aqua-shop notre927
2024-11-23 07:34:54
[代買] Pchome 24H 9折代買
helpbuy bastille
2024-11-23 07:28:02
Re: [請益] Lush洗髮皂
beautysalon umunya
2024-11-23 07:01:10