-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add solution and test-cases for problem 1253
- Loading branch information
Showing
3 changed files
with
83 additions
and
26 deletions.
There are no files selected for viewing
40 changes: 27 additions & 13 deletions
40
leetcode/1201-1300/1253.Reconstruct-a-2-Row-Binary-Matrix/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 44 additions & 2 deletions
46
leetcode/1201-1300/1253.Reconstruct-a-2-Row-Binary-Matrix/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,47 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(upper int, lower int, colsum []int) [][]int { | ||
res := make([][]int, 2) | ||
l := len(colsum) | ||
sum := 0 | ||
for i := range l { | ||
sum += colsum[i] | ||
} | ||
if sum != upper+lower { | ||
return nil | ||
} | ||
|
||
for i := range 2 { | ||
res[i] = make([]int, l) | ||
} | ||
|
||
for i := range l { | ||
if colsum[i] == 2 { | ||
if upper == 0 || lower == 0 { | ||
return nil | ||
} | ||
res[0][i] = 1 | ||
res[1][i] = 1 | ||
upper-- | ||
lower-- | ||
} | ||
} | ||
|
||
for i := range l { | ||
if colsum[i] == 1 { | ||
if upper > 0 { | ||
res[0][i] = 1 | ||
upper-- | ||
continue | ||
} | ||
if lower > 0 { | ||
res[1][i] = 1 | ||
lower-- | ||
continue | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters