Skip to content

Commit 9989b5c

Browse files
author
Aman burnwal
committed
commit
1 parent 4ca7103 commit 9989b5c

File tree

7 files changed

+146
-3
lines changed

7 files changed

+146
-3
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function bracket(n,open,close,str) {
2+
if(open === n && close === n){
3+
console.log(str);
4+
return;
5+
}
6+
if(open < n){
7+
bracket(n, open+1, close, str+"(")
8+
}
9+
if(open > close) {
10+
bracket(n, open, close+1, str+")")
11+
}
12+
}
13+
14+
a(3,0,0,"");
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// let n = -20;
2+
// for (let i = 0; i <= n; i++) {
3+
// let prime = 0;
4+
// for (let j = 2; j < i; j++) {
5+
// if (i % j === 0) {
6+
// prime = 1;
7+
// break;
8+
// }
9+
// }
10+
// if (i > 1 && prime == 0) {
11+
// console.log(i)
12+
// }
13+
// }
14+
15+
function primeis(num) {
16+
if(num <= 1) {
17+
return -1;
18+
}
19+
20+
for(let i = 2; i < num; i++) {
21+
let a = true;
22+
for(let j = 2; j <= i; j++ ) {
23+
if(i % j === 0) {
24+
a = false;
25+
break;
26+
}
27+
}
28+
if(a === true){
29+
console.log(i)
30+
}
31+
}
32+
33+
}
34+
35+
primeis(20)
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
function sum (num1, num2) {
2-
let carry = 1;
2+
while(num2 != 0) {
3+
let carry = num1 & num2
4+
num1 = num1 ^ num2;
5+
6+
num2 = carry << 1;
7+
}
8+
return num1;
39

4-
}
10+
}
11+
12+
console.log(sum(3,5));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function binomialCoefficient(n , k){
2+
//Base cases
3+
if(k > n){
4+
return 0;
5+
}
6+
7+
if(k === 0 || k === n){
8+
return 1;
9+
}
10+
11+
return binomialCoefficient(n - 1, k - 1) + binomialCoefficient(n - 1, k);
12+
}
13+
14+
console.log(binomialCoefficient(6, 4));
15+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function factorial(n){
2+
if(n === 0){
3+
return 1;
4+
}
5+
return n * factorial(n - 1);
6+
7+
}
8+
9+
console.log(factorial(5));

leet Code/alindrome_Linked_List.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Given the head of a singly linked list, return true if it is a palindrome.
2+
3+
4+
5+
// Example 1:
6+
7+
8+
// Input: head = [1,2,2,1]
9+
// Output: true
10+
// Example 2:
11+
12+
13+
// Input: head = [1,2]
14+
// Output: false
15+
16+
17+
// Constraints:
18+
19+
// The number of nodes in the list is in the range [1, 105].
20+
// 0 <= Node.val <= 9
21+
22+
23+
// Follow up: Could you do it in O(n) time and O(1) space?
24+
25+
26+
/**
27+
* Definition for singly-linked list.
28+
* function ListNode(val, next) {
29+
* this.val = (val===undefined ? 0 : val)
30+
* this.next = (next===undefined ? null : next)
31+
* }
32+
*/
33+
/**
34+
* @param {ListNode} head
35+
* @return {boolean}
36+
*/
37+
38+
39+
var isPalindrome = function (head) {
40+
let a = true;
41+
for (let i = 0; i < head.length / 2; i++) {
42+
if (head[i] !== head[head.length - 1 - i]) {
43+
a = false;
44+
break;
45+
}
46+
}
47+
return a;
48+
49+
};
50+
51+
let head = [1, 2]
52+
console.log(isPalindrome(head));
53+
54+
// let a = true;
55+
// for(let i = 0; i < head.length/ 2; i++){
56+
// if(head[i] !== head[head.length - 1 - i]){
57+
// a = false;
58+
// break;
59+
// }
60+
// }
61+
62+
// console.log(a);

leet Code/tempCodeRunnerFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"IXIV"
1+
toString(head);

0 commit comments

Comments
 (0)