位运算
059
这个作者很懒,什么都没留下…
展开
-
只出现一次的数字
引入HashMapclass Solution { public int singleNumber(int[] nums) { Map<Integer, Integer> countMap = new HashMap<>(); for(int num : nums){ if(!countMap.containsKey(num)){ countMap.put(num, 1); ..原创 2020-08-20 18:18:28 · 98 阅读 · 0 评论 -
划分为k个相等的子集(状态压缩)
一、题目二、代码class Solution { public boolean canPartitionKSubsets(int[] nums, int k) { if (k == 1) { return true; } int len = nums.length; Arrays.sort(nums); int sum = 0; for (int num : n..原创 2021-08-21 17:05:05 · 184 阅读 · 0 评论 -
颠倒二进制位
一、题目二、思路jdk自带函数public class Solution { // you need treat n as an unsigned value public int reverseBits(int n) { return Integer.reverse(n); }}位运算public class Solution { // you need treat n as an unsigned value ..原创 2021-08-14 18:08:14 · 48 阅读 · 0 评论