File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,26 @@ public class Solution {
198
198
}
199
199
```
200
200
201
+ #### Swift
202
+
203
+ ``` swift
204
+ class Solution {
205
+ func maxValue (_ grid : [[Int ]]) -> Int {
206
+ let m = grid.count
207
+ let n = grid[0 ].count
208
+ var f = [[Int ]](repeating : [Int ](repeating : 0 , count : n + 1 ), count : m + 1 )
209
+
210
+ for i in 1 ... m {
211
+ for j in 1 ... n {
212
+ f[i][j] = max (f[i - 1 ][j], f[i][j - 1 ]) + grid[i - 1 ][j - 1 ]
213
+ }
214
+ }
215
+
216
+ return f[m][n]
217
+ }
218
+ }
219
+ ```
220
+
201
221
<!-- tabs: end -->
202
222
203
223
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func maxValue( _ grid: [ [ Int ] ] ) -> Int {
3
+ let m = grid. count
4
+ let n = grid [ 0 ] . count
5
+ var f = [ [ Int] ] ( repeating: [ Int] ( repeating: 0 , count: n + 1 ) , count: m + 1 )
6
+
7
+ for i in 1 ... m {
8
+ for j in 1 ... n {
9
+ f [ i] [ j] = max ( f [ i - 1 ] [ j] , f [ i] [ j - 1 ] ) + grid[ i - 1 ] [ j - 1 ]
10
+ }
11
+ }
12
+
13
+ return f [ m] [ n]
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments