Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6ab3755

Browse files
feat: add typescript solution to lc problem: No.2044 (doocs#586)
No.2044.Count Number of Maximum Bitwise-OR Subsets
1 parent 9cee755 commit 6ab3755

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

‎solution/2000-2099/2044.Count Number of Maximum Bitwise-OR Subsets/README.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ class Solution {
117117
}
118118
```
119119

120+
### **TypeScript**
121+
122+
```ts
123+
function countMaxOrSubsets(nums: number[]): number {
124+
let n = nums.length;
125+
let max = 0;
126+
for (let i = 0; i < n; i++) {
127+
max |= nums[i];
128+
}
129+
let ans = 0;
130+
function dfs (pre: number, depth: number): void {
131+
if (depth == n) {
132+
if (pre == max) ++ans;
133+
return;
134+
}
135+
dfs(pre, depth + 1);
136+
dfs(pre | nums[depth], depth + 1);
137+
}
138+
dfs(0, 0);
139+
return ans;
140+
};
141+
```
142+
120143
### **C++**
121144

122145
```cpp

‎solution/2000-2099/2044.Count Number of Maximum Bitwise-OR Subsets/README_EN.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,29 @@ class Solution {
107107
}
108108
```
109109

110+
### **TypeScript**
111+
112+
```ts
113+
function countMaxOrSubsets(nums: number[]): number {
114+
let n = nums.length;
115+
let max = 0;
116+
for (let i = 0; i < n; i++) {
117+
max |= nums[i];
118+
}
119+
let ans = 0;
120+
function dfs (pre: number, depth: number): void {
121+
if (depth == n) {
122+
if (pre == max) ++ans;
123+
return;
124+
}
125+
dfs(pre, depth + 1);
126+
dfs(pre | nums[depth], depth + 1);
127+
}
128+
dfs(0, 0);
129+
return ans;
130+
};
131+
```
132+
110133
### **C++**
111134

112135
```cpp
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function countMaxOrSubsets(nums: number[]): number {
2+
let n = nums.length;
3+
let max = 0;
4+
for (let i = 0; i < n; i++) {
5+
max |= nums[i];
6+
}
7+
let ans = 0;
8+
function dfs (pre: number, depth: number): void {
9+
if (depth == n) {
10+
if (pre == max) ++ans;
11+
return;
12+
}
13+
dfs(pre, depth + 1);
14+
dfs(pre | nums[depth], depth + 1);
15+
}
16+
dfs(0, 0);
17+
return ans;
18+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /