@@ -52,13 +52,89 @@ Another possible matrix is: [[1,2],
52
52
### ** Python3**
53
53
54
54
``` python
55
-
55
+ class Solution :
56
+ def restoreMatrix (self , rowSum : List[int ], colSum : List[int ]) -> List[List[int ]]:
57
+ m, n = len (rowSum), len (colSum)
58
+ ans = [[0 ] * n for _ in range (m)]
59
+ for i in range (m):
60
+ for j in range (n):
61
+ x = min (rowSum[i], colSum[j])
62
+ ans[i][j] = x
63
+ rowSum[i] -= x
64
+ colSum[j] -= x
65
+ return ans
56
66
```
57
67
58
68
### ** Java**
59
69
60
70
``` java
71
+ class Solution {
72
+ public int [][] restoreMatrix (int [] rowSum , int [] colSum ) {
73
+ int m = rowSum. length;
74
+ int n = colSum. length;
75
+ int [][] ans = new int [m][n];
76
+ for (int i = 0 ; i < m; ++ i) {
77
+ for (int j = 0 ; j < n; ++ j) {
78
+ int x = Math . min(rowSum[i], colSum[j]);
79
+ ans[i][j] = x;
80
+ rowSum[i] -= x;
81
+ colSum[j] -= x;
82
+ }
83
+ }
84
+ return ans;
85
+ }
86
+ }
87
+ ```
88
+
89
+ ### ** C++**
90
+
91
+ ``` cpp
92
+ class Solution {
93
+ public:
94
+ vector<vector<int >> restoreMatrix(vector<int >& rowSum, vector<int >& colSum) {
95
+ int m = rowSum.size(), n = colSum.size();
96
+ vector<vector<int >> ans(m, vector<int >(n));
97
+ for (int i = 0; i < m; ++i)
98
+ {
99
+ for (int j = 0; j < n; ++j)
100
+ {
101
+ int x = min(rowSum[ i] , colSum[ j] );
102
+ ans[ i] [ j ] = x;
103
+ rowSum[ i] -= x;
104
+ colSum[ j] -= x;
105
+ }
106
+ }
107
+ return ans;
108
+ }
109
+ };
110
+ ```
61
111
112
+ ### **Go**
113
+
114
+ ```go
115
+ func restoreMatrix(rowSum []int, colSum []int) [][]int {
116
+ m, n := len(rowSum), len(colSum)
117
+ ans := make([][]int, m)
118
+ for i := range ans {
119
+ ans[i] = make([]int, n)
120
+ }
121
+ for i := range rowSum {
122
+ for j := range colSum {
123
+ x := min(rowSum[i], colSum[j])
124
+ ans[i][j] = x
125
+ rowSum[i] -= x
126
+ colSum[j] -= x
127
+ }
128
+ }
129
+ return ans
130
+ }
131
+
132
+ func min(a, b int) int {
133
+ if a < b {
134
+ return a
135
+ }
136
+ return b
137
+ }
62
138
```
63
139
64
140
### ** ...**
0 commit comments