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

Commit7506551

Browse files
refactor 474
1 parent8c536fb commit7506551

File tree

1 file changed

+13
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+13
-0
lines changed

‎src/main/java/com/fishercoder/solutions/_474.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
publicclass_474 {
44
publicstaticclassSolution1 {
5+
/**
6+
* credit: https://leetcode.com/problems/ones-and-zeroes/discuss/95811/Java-Iterative-DP-Solution-O(mn)-Space and
7+
* https://leetcode.com/problems/ones-and-zeroes/discuss/95811/Java-Iterative-DP-Solution-O(mn)-Space/100352
8+
* <p>
9+
* The problem can be interpreted as:
10+
* What's the max number of str can we pick from strs with limitation of m "0"s and n "1"s.
11+
*
12+
* Thus we can define dp[i][j] as it stands for max number of str can we pick from strs with limitation of i "0"s and j "1"s.
13+
*
14+
* For each str, assume it has a "0"s and b "1"s, we update the dp array iteratively
15+
* and set dp[i][j] = Math.max(dp[i][j], dp[i - a][j - b] + 1).
16+
* So at the end, dp[m][n] is the answer.
17+
*/
518
publicintfindMaxForm(String[]strs,intm,intn) {
619
int[][]dp =newint[m +1][n +1];
720
for (Stringstr :strs) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp