Skip to content

Commit 7506551

Browse files
refactor 474
1 parent 8c536fb commit 7506551

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
public class _474 {
44
public static class Solution1 {
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
public int findMaxForm(String[] strs, int m, int n) {
619
int[][] dp = new int[m + 1][n + 1];
720
for (String str : strs) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy