Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.29 KB

leetcode_363.md

File metadata and controls

58 lines (40 loc) · 1.29 KB

a

https://leetcode.cn/problems/sum-of-values-at-indices-with-k-set-bits/description/

class Solution {
    public int sumIndicesWithKSetBits(List<Integer> nums, int k) {
        int res = 0;
        for (int i = 0; i < nums.size(); i ++) {
            int x = nums.get(i);
            if (getone(i) == k) {
                res += x;
            }
        }
        return res;
    }
    public int getone(int x) {
        int cnt = 0;
        while (x != 0) {
            if ((x & 1) == 1) cnt ++;
            x >>= 1;
        }
        return cnt;
    }
}

b

https://leetcode.cn/problems/happy-students/description/

c

https://leetcode.cn/problems/maximum-number-of-alloys/description/

d

https://leetcode.cn/problems/maximum-element-sum-of-a-complete-subset-of-indices/description/