Skip to content

Commit

Permalink
add js solution for findMaxForm
Browse files Browse the repository at this point in the history
  • Loading branch information
jackeyjia authored Jul 5, 2021
1 parent 1da6ff7 commit 14154b9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions problems/0474.一和零.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,35 @@ func max(a,b int) int {
}
```

Javascript:
```javascript
const findMaxForm = (strs, m, n) => {
const dp = Array.from(Array(m+1), () => Array(n+1).fill(0));
let numOfZeros, numOfOnes;

for(let str of strs) {
numOfZeros = 0;
numOfOnes = 0;

for(let c of str) {
if (c === '0') {
numOfZeros++;
} else {
numOfOnes++;
}
}

for(let i = m; i >= numOfZeros; i--) {
for(let j = n; j >= numOfOnes; j--) {
dp[i][j] = Math.max(dp[i][j], dp[i - numOfZeros][j - numOfOnes] + 1);
}
}
}

return dp[m][n];
};
```



-----------------------
Expand Down

0 comments on commit 14154b9

Please sign in to comment.