We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 44bb3ba commit 7365cebCopy full SHA for 7365ceb
779-k-th-symbol-in-grammar.js
@@ -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