Skip to content

Commit 7365ceb

Browse files
authored
Create 779-k-th-symbol-in-grammar.js
1 parent 44bb3ba commit 7365ceb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

779-k-th-symbol-in-grammar.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @param {number} N
3+
* @param {number} K
4+
* @return {number}
5+
*/
6+
const kthGrammar = function(N, K) {
7+
if (N === 1) return 0;
8+
if (K % 2 === 0) return (kthGrammar(N - 1, K / 2) === 0) ? 1 : 0;
9+
else return (kthGrammar(N - 1, (K + 1) / 2) === 0) ? 0 : 1;
10+
};

0 commit comments

Comments
 (0)