






















思路 Hash记录所有数的数量,然后排序后依次遍历,检查能达到的最大长度,检查过程中移除该值(因为不会有更长的)。 然而后来发现,排序+移除剪枝是在自娱自乐,还不如直接遍历更快 🤣 代码 class Solution { public int maximumLength(int[] nums) { HashMap<Integer, Integer> map = new HashMap<>(); for (int num : nums) { map.merge(num, 1, Integer::sum); } int ans = 0; if (map.containsKey(1)) { int cnt = map.get(1); if ((cnt & 1) == 1) { ans = cnt; } else { ans = c...
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。