File tree Expand file tree Collapse file tree 1 file changed +2
-3
lines changed
src/main/kotlin/g0501_0600/s0546_remove_boxes Expand file tree Collapse file tree 1 file changed +2
-3
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ package g0501_0600.s0546_remove_boxes
33// #Hard #Array #Dynamic_Programming #Memoization
44// #2023_01_17_Time_283_ms_(100.00%)_Space_46.9_MB_(100.00%)
55
6- internal class Solution {
6+ @Suppress(" NAME_SHADOWING" )
7+ class Solution {
78 // dp for memoization
89 lateinit var dp: Array <Array <IntArray >>
910 fun removeBoxes (boxes : IntArray ): Int {
@@ -30,12 +31,10 @@ internal class Solution {
3031 i++
3132 streak++
3233 }
33-
3434 // memoization
3535 if (dp[i][j][streak] > 0 ) {
3636 return dp[i][j][streak]
3737 }
38-
3938 // we calculate the ans here which is streak (length of similar elements) and move
4039 // forward to the remaining block through recursion
4140 var ans = (streak + 1 ) * (streak + 1 ) + get(boxes, i + 1 , j, 0 )
You can’t perform that action at this time.
0 commit comments