notes/OJ notes/pages/Bit-Manipulation count true trick.md

34 lines
553 B
Markdown
Raw Permalink Normal View History

2022-07-22 15:36:57 +08:00
# Bit-Manipulation count true trick
#### 2022-07-22 15:11
> ##### Algorithms:
2022-09-03 15:41:36 +08:00
>
> #algorithm #bit_manipulation
>
2022-07-22 15:36:57 +08:00
> ##### Data Structure:
2022-09-03 15:41:36 +08:00
>
> #DS #bitset
>
2022-07-22 15:36:57 +08:00
> ##### Difficulty:
2022-09-03 15:41:36 +08:00
>
2022-09-06 20:22:48 +08:00
> #CS_analysis #difficulty_easy
2022-09-03 15:41:36 +08:00
>
2022-07-22 15:36:57 +08:00
> ##### Additional tags:
##### Related problems:
2022-09-03 15:41:36 +08:00
2022-07-22 15:36:57 +08:00
### What is Bit-Manipulation count true trick?
(n & (n - 1))
### How does Bit-Manipulation count true trick work?
#### validate if the number is power of 2
See [[Leetcode Power-of-Two#Method 1 using masking]]
#### Counting 1
2022-09-03 15:41:36 +08:00
See [[Leetcode Number-of-1-Bits#Method 2 n n - 1 method]]