-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path779.java
More file actions
16 lines (16 loc) · 583 Bytes
/
779.java
File metadata and controls
16 lines (16 loc) · 583 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
__________________________________________________________________________________________________
0ms
class Solution {
public int kthGrammar(int N, int K) {
return Integer.bitCount(K-1) & 1;
}
}
__________________________________________________________________________________________________
sample 31584 kb submission
class Solution {
public int kthGrammar(int N, int K) {
if (N == 1) return 0;
return (1 - (K%2)) ^ kthGrammar(N-1, (K+1)/2);
}
}
__________________________________________________________________________________________________