Skip to content

Commit

Permalink
feat: add typescript solution to lc problem: No.2044 (#586)
Browse files Browse the repository at this point in the history
No.2044.Count Number of Maximum Bitwise-OR Subsets
  • Loading branch information
zhaocchen authored Oct 19, 2021
1 parent 9cee755 commit 6ab3755
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ class Solution {
}
```

### **TypeScript**

```ts
function countMaxOrSubsets(nums: number[]): number {
let n = nums.length;
let max = 0;
for (let i = 0; i < n; i++) {
max |= nums[i];
}
let ans = 0;
function dfs (pre: number, depth: number): void {
if (depth == n) {
if (pre == max) ++ans;
return;
}
dfs(pre, depth + 1);
dfs(pre | nums[depth], depth + 1);
}
dfs(0, 0);
return ans;
};
```

### **C++**

```cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,29 @@ class Solution {
}
```

### **TypeScript**

```ts
function countMaxOrSubsets(nums: number[]): number {
let n = nums.length;
let max = 0;
for (let i = 0; i < n; i++) {
max |= nums[i];
}
let ans = 0;
function dfs (pre: number, depth: number): void {
if (depth == n) {
if (pre == max) ++ans;
return;
}
dfs(pre, depth + 1);
dfs(pre | nums[depth], depth + 1);
}
dfs(0, 0);
return ans;
};
```

### **C++**

```cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function countMaxOrSubsets(nums: number[]): number {
let n = nums.length;
let max = 0;
for (let i = 0; i < n; i++) {
max |= nums[i];
}
let ans = 0;
function dfs (pre: number, depth: number): void {
if (depth == n) {
if (pre == max) ++ans;
return;
}
dfs(pre, depth + 1);
dfs(pre | nums[depth], depth + 1);
}
dfs(0, 0);
return ans;
};

0 comments on commit 6ab3755

Please sign in to comment.