Movatterモバイル変換


[0]ホーム

URL:


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

Commit4598c47

Browse files
Merge pull requestyoungyangyang04#469 from jackeyjia/patch-3
add js solution for findMaxForm
2 parentsb4d2f98 +14154b9 commit4598c47

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎problems/0474.一和零.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,35 @@ func max(a,b int) int {
244244
}
245245
```
246246

247+
Javascript:
248+
```javascript
249+
constfindMaxForm= (strs,m,n)=> {
250+
constdp=Array.from(Array(m+1), ()=>Array(n+1).fill(0));
251+
let numOfZeros, numOfOnes;
252+
253+
for(let strof strs) {
254+
numOfZeros=0;
255+
numOfOnes=0;
256+
257+
for(let cof str) {
258+
if (c==='0') {
259+
numOfZeros++;
260+
}else {
261+
numOfOnes++;
262+
}
263+
}
264+
265+
for(let i= m; i>= numOfZeros; i--) {
266+
for(let j= n; j>= numOfOnes; j--) {
267+
dp[i][j]=Math.max(dp[i][j], dp[i- numOfZeros][j- numOfOnes]+1);
268+
}
269+
}
270+
}
271+
272+
return dp[m][n];
273+
};
274+
```
275+
247276

248277

249278
-----------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp