package com.leetcode

import java.util.*

// https://github.com/antop-dev/algorithm/issues/311
class P311 {
    private val dy = intArrayOf(-1, +0, +1, +0)
    private val dx = intArrayOf(+0, +1, +0, -1)
    fun shortestPath(grid: Array<IntArray>, k: Int): Int {
        val m = grid.size
        val n = grid[0].size
        val memo = Array(m) { Array(n) { intArrayOf(m * n, m * n) } }
        // [y좌표, x좌표, 장애물제거수]
        val queue = LinkedList<IntArray>()
        queue += intArrayOf(0, 0, 0)

        var move = 0 // 이동 수

        loop@ while (queue.isNotEmpty()) {
            val size = queue.size
            repeat(size) {
                val (y, x, eliminate) = queue.poll()
                // 목적지 도착
                if (y == m - 1 && x == n - 1) { // 도착
                    return move
                }
                // 네방향 체크
                dy.zip(dx) { a, b ->
                    val ny = y + a
                    val nx = x + b

                    if (ny in 0 until m && nx in 0 until n) {
                        val next = intArrayOf(ny, nx, eliminate)
                        if (grid[ny][nx] == 1) { // 벽
                            if (eliminate < k) { // 장애물 제거 가능
                                next[2]++
                            } else { // 장애물 제거 불가능
                                return@zip
                            }
                        }
                        memo[ny][nx][0] = move
                        memo[ny][nx][1] = next[2]
                        queue += next
                    }
                }
            }
            move++
        }
        return -1
    }

}

Compiled from "P311.kt"
public final class com.leetcode.P311 {
  private final int[] dy;

  private final int[] dx;

  public com.leetcode.P311();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iconst_4
       6: newarray       int
       8: astore_1
       9: aload_1
      10: iconst_0
      11: iconst_m1
      12: iastore
      13: aload_1
      14: iconst_1
      15: iconst_0
      16: iastore
      17: aload_1
      18: iconst_2
      19: iconst_1
      20: iastore
      21: aload_1
      22: iconst_3
      23: iconst_0
      24: iastore
      25: aload_1
      26: putfield      #12                 // Field dy:[I
      29: aload_0
      30: iconst_4
      31: newarray       int
      33: astore_1
      34: aload_1
      35: iconst_0
      36: iconst_0
      37: iastore
      38: aload_1
      39: iconst_1
      40: iconst_1
      41: iastore
      42: aload_1
      43: iconst_2
      44: iconst_0
      45: iastore
      46: aload_1
      47: iconst_3
      48: iconst_m1
      49: iastore
      50: aload_1
      51: putfield      #15                 // Field dx:[I
      54: return

  public final int shortestPath(int[][], int);
    Code:
       0: aload_1
       1: ldc           #22                 // String grid
       3: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #30                 // class "[Ljava/lang/Object;"
      10: arraylength
      11: istore_3
      12: aload_1
      13: iconst_0
      14: aaload
      15: arraylength
      16: istore        4
      18: iconst_0
      19: istore        6
      21: iload_3
      22: anewarray     #32                 // class "[[I"
      25: astore        7
      27: iload         6
      29: iload_3
      30: if_icmpge     113
      33: iload         6
      35: istore        8
      37: aload         7
      39: iload         8
      41: iconst_0
      42: istore        9
      44: iload         4
      46: anewarray     #33                 // class "[I"
      49: astore        10
      51: istore        31
      53: astore        30
      55: iload         9
      57: iload         4
      59: if_icmpge     100
      62: iload         9
      64: istore        11
      66: aload         10
      68: iload         11
      70: iconst_2
      71: newarray       int
      73: astore        12
      75: aload         12
      77: iconst_0
      78: iload_3
      79: iload         4
      81: imul
      82: iastore
      83: aload         12
      85: iconst_1
      86: iload_3
      87: iload         4
      89: imul
      90: iastore
      91: aload         12
      93: aastore
      94: iinc          9, 1
      97: goto          55
     100: aload         30
     102: iload         31
     104: aload         10
     106: aastore
     107: iinc          6, 1
     110: goto          27
     113: aload         7
     115: astore        5
     117: new           #35                 // class java/util/LinkedList
     120: dup
     121: invokespecial #36                 // Method java/util/LinkedList."<init>":()V
     124: astore        6
     126: aload         6
     128: checkcast     #38                 // class java/util/Collection
     131: astore        7
     133: iconst_3
     134: newarray       int
     136: astore        8
     138: aload         8
     140: iconst_0
     141: iconst_0
     142: iastore
     143: aload         8
     145: iconst_1
     146: iconst_0
     147: iastore
     148: aload         8
     150: iconst_2
     151: iconst_0
     152: iastore
     153: aload         7
     155: aload         8
     157: invokeinterface #42,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     162: pop
     163: iconst_0
     164: istore        7
     166: aload         6
     168: checkcast     #38                 // class java/util/Collection
     171: invokeinterface #46,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     176: ifne          183
     179: iconst_1
     180: goto          184
     183: iconst_0
     184: ifeq          540
     187: aload         6
     189: invokevirtual #50                 // Method java/util/LinkedList.size:()I
     192: istore        8
     194: iconst_0
     195: istore        9
     197: iload         9
     199: iload         8
     201: if_icmpge     527
     204: iload         9
     206: istore        10
     208: iconst_0
     209: istore        11
     211: aload         6
     213: invokevirtual #54                 // Method java/util/LinkedList.poll:()Ljava/lang/Object;
     216: checkcast     #33                 // class "[I"
     219: astore        12
     221: aload         12
     223: invokestatic  #58                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     226: aload         12
     228: iconst_0
     229: iaload
     230: istore        13
     232: aload         12
     234: iconst_1
     235: iaload
     236: istore        14
     238: aload         12
     240: iconst_2
     241: iaload
     242: istore        15
     244: iload         13
     246: iload_3
     247: iconst_1
     248: isub
     249: if_icmpne     264
     252: iload         14
     254: iload         4
     256: iconst_1
     257: isub
     258: if_icmpne     264
     261: iload         7
     263: ireturn
     264: aload_0
     265: getfield      #12                 // Field dy:[I
     268: astore        16
     270: aload_0
     271: getfield      #15                 // Field dx:[I
     274: astore        17
     276: iconst_0
     277: istore        18
     279: aload         16
     281: arraylength
     282: aload         17
     284: arraylength
     285: invokestatic  #64                 // Method java/lang/Math.min:(II)I
     288: istore        19
     290: new           #66                 // class java/util/ArrayList
     293: dup
     294: iload         19
     296: invokespecial #69                 // Method java/util/ArrayList."<init>":(I)V
     299: astore        20
     301: iconst_0
     302: istore        21
     304: iload         21
     306: iload         19
     308: if_icmpge     514
     311: aload         20
     313: aload         16
     315: iload         21
     317: iaload
     318: aload         17
     320: iload         21
     322: iaload
     323: istore        22
     325: istore        23
     327: astore        24
     329: iconst_0
     330: istore        25
     332: iload         13
     334: iload         23
     336: iadd
     337: istore        26
     339: iload         14
     341: iload         22
     343: iadd
     344: istore        27
     346: iconst_0
     347: iload         26
     349: if_icmpgt     366
     352: iload         26
     354: iload_3
     355: if_icmpge     362
     358: iconst_1
     359: goto          367
     362: iconst_0
     363: goto          367
     366: iconst_0
     367: ifeq          498
     370: iconst_0
     371: iload         27
     373: if_icmpgt     391
     376: iload         27
     378: iload         4
     380: if_icmpge     387
     383: iconst_1
     384: goto          392
     387: iconst_0
     388: goto          392
     391: iconst_0
     392: ifeq          498
     395: iconst_3
     396: newarray       int
     398: astore        28
     400: aload         28
     402: iconst_0
     403: iload         26
     405: iastore
     406: aload         28
     408: iconst_1
     409: iload         27
     411: iastore
     412: aload         28
     414: iconst_2
     415: iload         15
     417: iastore
     418: aload         28
     420: astore        29
     422: aload_1
     423: iload         26
     425: aaload
     426: iload         27
     428: iaload
     429: iconst_1
     430: if_icmpne     459
     433: iload         15
     435: iload_2
     436: if_icmpge     456
     439: aload         29
     441: iconst_2
     442: iaload
     443: istore        28
     445: aload         29
     447: iconst_2
     448: iload         28
     450: iconst_1
     451: iadd
     452: iastore
     453: goto          459
     456: goto          499
     459: aload         5
     461: iload         26
     463: aaload
     464: iload         27
     466: aaload
     467: iconst_0
     468: iload         7
     470: iastore
     471: aload         5
     473: iload         26
     475: aaload
     476: iload         27
     478: aaload
     479: iconst_1
     480: aload         29
     482: iconst_2
     483: iaload
     484: iastore
     485: aload         6
     487: checkcast     #38                 // class java/util/Collection
     490: aload         29
     492: invokeinterface #42,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     497: pop
     498: nop
     499: aload         24
     501: getstatic     #75                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     504: invokevirtual #76                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     507: pop
     508: iinc          21, 1
     511: goto          304
     514: aload         20
     516: checkcast     #78                 // class java/util/List
     519: pop
     520: nop
     521: iinc          9, 1
     524: goto          197
     527: iload         7
     529: istore        9
     531: iload         9
     533: iconst_1
     534: iadd
     535: istore        7
     537: goto          166
     540: iconst_m1
     541: ireturn
}


package com.leetcode

// https://leetcode.com/problems/predict-the-winner/
class P486 {
    fun PredictTheWinner(nums: IntArray): Boolean {
        if (nums.size <= 2) return true
        return predict(nums, 0, 0, nums.lastIndex, 1) >= 0
    }

    private fun predict(nums: IntArray, score: Int, l: Int, r: Int, t: Int): Int {
        if (l > r) return score
        return if (t % 2 == 0) { // p1
            maxOf(
                predict(nums, score + nums[l], l + 1, r, t * -1),
                predict(nums, score + nums[r], l, r - 1, t * -1)
            )
        } else { // p2
            minOf(
                predict(nums, score - nums[l], l + 1, r, t * -1),
                predict(nums, score - nums[r], l, r - 1, t * -1)
            )
        }
    }

}

Compiled from "P486.kt"
public final class com.leetcode.P486 {
  public com.leetcode.P486();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final boolean PredictTheWinner(int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String nums
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: arraylength
       8: iconst_2
       9: if_icmpgt     14
      12: iconst_1
      13: ireturn
      14: aload_0
      15: aload_1
      16: iconst_0
      17: iconst_0
      18: aload_1
      19: invokestatic  #27                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      22: iconst_1
      23: invokespecial #31                 // Method predict:([IIIII)I
      26: iflt          33
      29: iconst_1
      30: goto          34
      33: iconst_0
      34: ireturn

  private final int predict(int[], int, int, int, int);
    Code:
       0: iload_3
       1: iload         4
       3: if_icmple     8
       6: iload_2
       7: ireturn
       8: iload         5
      10: iconst_2
      11: irem
      12: ifne          61
      15: nop
      16: aload_0
      17: aload_1
      18: iload_2
      19: aload_1
      20: iload_3
      21: iaload
      22: iadd
      23: iload_3
      24: iconst_1
      25: iadd
      26: iload         4
      28: iload         5
      30: iconst_m1
      31: imul
      32: invokespecial #31                 // Method predict:([IIIII)I
      35: aload_0
      36: aload_1
      37: iload_2
      38: aload_1
      39: iload         4
      41: iaload
      42: iadd
      43: iload_3
      44: iload         4
      46: iconst_1
      47: isub
      48: iload         5
      50: iconst_m1
      51: imul
      52: invokespecial #31                 // Method predict:([IIIII)I
      55: invokestatic  #38                 // Method java/lang/Math.max:(II)I
      58: goto          104
      61: nop
      62: aload_0
      63: aload_1
      64: iload_2
      65: aload_1
      66: iload_3
      67: iaload
      68: isub
      69: iload_3
      70: iconst_1
      71: iadd
      72: iload         4
      74: iload         5
      76: iconst_m1
      77: imul
      78: invokespecial #31                 // Method predict:([IIIII)I
      81: aload_0
      82: aload_1
      83: iload_2
      84: aload_1
      85: iload         4
      87: iaload
      88: isub
      89: iload_3
      90: iload         4
      92: iconst_1
      93: isub
      94: iload         5
      96: iconst_m1
      97: imul
      98: invokespecial #31                 // Method predict:([IIIII)I
     101: invokestatic  #41                 // Method java/lang/Math.min:(II)I
     104: ireturn
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/277
class P1314 {
    fun matrixBlockSum(mat: Array<IntArray>, k: Int): Array<IntArray> {
        val dp = Array(mat.size) { i -> IntArray(mat[i].size) }.apply {
            this[0][0] = mat[0][0]
            for (i in 1 until mat.size) this[i][0] = this[i - 1][0] + mat[i][0]
            for (i in 1 until mat[0].size) this[0][i] = this[0][i - 1] + mat[0][i]
            for (i in 1 until mat.size) {
                for (j in 1 until mat[i].size) {
                    this[i][j] = this[i - 1][j] + this[i][j - 1] + mat[i][j] - this[i - 1][j - 1]
                }
            }
        }

        return Array(mat.size) { i -> IntArray(mat[i].size) }.apply {
            for (i in mat.indices) {
                for (j in mat[i].indices) {
                    val y = minOf(i + k, dp.lastIndex)
                    val x = minOf(j + k, dp[i].lastIndex)
                    this[i][j] = dp[y][x]

                    val r = i - k - 1
                    val c = j - k - 1
                    if (r >= 0) this[i][j] -= dp[r][x]
                    if (c >= 0) this[i][j] -= dp[y][c]
                    if (r >= 0 && c >= 0) this[i][j] += dp[r][c]
                }
            }
        }
    }
}

Compiled from "P1314.kt"
public final class com.leetcode.P1314 {
  public com.leetcode.P1314();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int[][] matrixBlockSum(int[][], int);
    Code:
       0: aload_1
       1: ldc           #15                 // String mat
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore        4
       9: aload_1
      10: checkcast     #23                 // class "[Ljava/lang/Object;"
      13: arraylength
      14: istore        5
      16: iload         5
      18: anewarray     #25                 // class "[I"
      21: astore        6
      23: iload         4
      25: iload         5
      27: if_icmpge     52
      30: iload         4
      32: istore        7
      34: aload         6
      36: iload         7
      38: aload_1
      39: iload         7
      41: aaload
      42: arraylength
      43: newarray       int
      45: aastore
      46: iinc          4, 1
      49: goto          23
      52: aload         6
      54: astore        4
      56: aload         4
      58: checkcast     #27                 // class "[[I"
      61: astore        5
      63: iconst_0
      64: istore        6
      66: aload         5
      68: iconst_0
      69: aaload
      70: iconst_0
      71: aload_1
      72: iconst_0
      73: aaload
      74: iconst_0
      75: iaload
      76: iastore
      77: iconst_1
      78: istore        7
      80: aload_1
      81: checkcast     #23                 // class "[Ljava/lang/Object;"
      84: arraylength
      85: istore        8
      87: iload         7
      89: iload         8
      91: if_icmpge     123
      94: aload         5
      96: iload         7
      98: aaload
      99: iconst_0
     100: aload         5
     102: iload         7
     104: iconst_1
     105: isub
     106: aaload
     107: iconst_0
     108: iaload
     109: aload_1
     110: iload         7
     112: aaload
     113: iconst_0
     114: iaload
     115: iadd
     116: iastore
     117: iinc          7, 1
     120: goto          87
     123: iconst_1
     124: istore        7
     126: aload_1
     127: iconst_0
     128: aaload
     129: arraylength
     130: istore        8
     132: iload         7
     134: iload         8
     136: if_icmpge     168
     139: aload         5
     141: iconst_0
     142: aaload
     143: iload         7
     145: aload         5
     147: iconst_0
     148: aaload
     149: iload         7
     151: iconst_1
     152: isub
     153: iaload
     154: aload_1
     155: iconst_0
     156: aaload
     157: iload         7
     159: iaload
     160: iadd
     161: iastore
     162: iinc          7, 1
     165: goto          132
     168: iconst_1
     169: istore        7
     171: aload_1
     172: checkcast     #23                 // class "[Ljava/lang/Object;"
     175: arraylength
     176: istore        8
     178: iload         7
     180: iload         8
     182: if_icmpge     264
     185: iconst_1
     186: istore        9
     188: aload_1
     189: iload         7
     191: aaload
     192: arraylength
     193: istore        10
     195: iload         9
     197: iload         10
     199: if_icmpge     258
     202: aload         5
     204: iload         7
     206: aaload
     207: iload         9
     209: aload         5
     211: iload         7
     213: iconst_1
     214: isub
     215: aaload
     216: iload         9
     218: iaload
     219: aload         5
     221: iload         7
     223: aaload
     224: iload         9
     226: iconst_1
     227: isub
     228: iaload
     229: iadd
     230: aload_1
     231: iload         7
     233: aaload
     234: iload         9
     236: iaload
     237: iadd
     238: aload         5
     240: iload         7
     242: iconst_1
     243: isub
     244: aaload
     245: iload         9
     247: iconst_1
     248: isub
     249: iaload
     250: isub
     251: iastore
     252: iinc          9, 1
     255: goto          195
     258: iinc          7, 1
     261: goto          178
     264: nop
     265: aload         4
     267: checkcast     #27                 // class "[[I"
     270: astore_3
     271: iconst_0
     272: istore        4
     274: aload_1
     275: checkcast     #23                 // class "[Ljava/lang/Object;"
     278: arraylength
     279: istore        5
     281: iload         5
     283: anewarray     #25                 // class "[I"
     286: astore        6
     288: iload         4
     290: iload         5
     292: if_icmpge     317
     295: iload         4
     297: istore        7
     299: aload         6
     301: iload         7
     303: aload_1
     304: iload         7
     306: aaload
     307: arraylength
     308: newarray       int
     310: aastore
     311: iinc          4, 1
     314: goto          288
     317: aload         6
     319: astore        4
     321: aload         4
     323: checkcast     #27                 // class "[[I"
     326: astore        5
     328: iconst_0
     329: istore        6
     331: iconst_0
     332: istore        7
     334: aload_1
     335: checkcast     #23                 // class "[Ljava/lang/Object;"
     338: arraylength
     339: istore        8
     341: iload         7
     343: iload         8
     345: if_icmpge     547
     348: iconst_0
     349: istore        9
     351: aload_1
     352: iload         7
     354: aaload
     355: arraylength
     356: istore        10
     358: iload         9
     360: iload         10
     362: if_icmpge     541
     365: iload         7
     367: iload_2
     368: iadd
     369: aload_3
     370: checkcast     #23                 // class "[Ljava/lang/Object;"
     373: invokestatic  #33                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     376: invokestatic  #39                 // Method java/lang/Math.min:(II)I
     379: istore        11
     381: iload         9
     383: iload_2
     384: iadd
     385: aload_3
     386: iload         7
     388: aaload
     389: invokestatic  #42                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
     392: invokestatic  #39                 // Method java/lang/Math.min:(II)I
     395: istore        12
     397: aload         5
     399: iload         7
     401: aaload
     402: iload         9
     404: aload_3
     405: iload         11
     407: aaload
     408: iload         12
     410: iaload
     411: iastore
     412: iload         7
     414: iload_2
     415: isub
     416: iconst_1
     417: isub
     418: istore        13
     420: iload         9
     422: iload_2
     423: isub
     424: iconst_1
     425: isub
     426: istore        14
     428: iload         13
     430: iflt          462
     433: aload         5
     435: iload         7
     437: aaload
     438: astore        15
     440: iload         9
     442: istore        16
     444: aload         15
     446: iload         16
     448: aload         15
     450: iload         16
     452: iaload
     453: aload_3
     454: iload         13
     456: aaload
     457: iload         12
     459: iaload
     460: isub
     461: iastore
     462: iload         14
     464: iflt          496
     467: aload         5
     469: iload         7
     471: aaload
     472: astore        15
     474: iload         9
     476: istore        16
     478: aload         15
     480: iload         16
     482: aload         15
     484: iload         16
     486: iaload
     487: aload_3
     488: iload         11
     490: aaload
     491: iload         14
     493: iaload
     494: isub
     495: iastore
     496: iload         13
     498: iflt          535
     501: iload         14
     503: iflt          535
     506: aload         5
     508: iload         7
     510: aaload
     511: astore        15
     513: iload         9
     515: istore        16
     517: aload         15
     519: iload         16
     521: aload         15
     523: iload         16
     525: iaload
     526: aload_3
     527: iload         13
     529: aaload
     530: iload         14
     532: iaload
     533: iadd
     534: iastore
     535: iinc          9, 1
     538: goto          358
     541: iinc          7, 1
     544: goto          341
     547: nop
     548: aload         4
     550: checkcast     #27                 // class "[[I"
     553: areturn
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/286
class P959 {
    fun regionsBySlashes(grid: Array<String>): Int {
        val n = grid.size

        val arr = Array(n * 3) { IntArray(n * 3) }
        for (i in 0 until (n * n)) {
            val p = intArrayOf(i / n * 3, i % n * 3)
            when (grid[i / n][i % n]) {
                '\\' -> {
                    arr[p[0]][p[1]] = 1
                    arr[p[0] + 1][p[1] + 1] = 1
                    arr[p[0] + 2][p[1] + 2] = 1
                }
                '/' -> {
                    arr[p[0]][p[1] + 2] = 1
                    arr[p[0] + 1][p[1] + 1] = 1
                    arr[p[0] + 2][p[1]] = 1
                }
            }
        }

        var answer = 0
        for (i in arr.indices) {
            for (j in arr[i].indices) {
                if (arr[i][j] == 0) {
                    dfs(arr, i, j)
                    answer++
                }
            }
        }
        return answer
    }

    private fun dfs(grid: Array<IntArray>, i: Int, j: Int) {
        if (i !in 0..grid.lastIndex) return
        if (j !in 0..grid[i].lastIndex) return
        if (grid[i][j] == 1) return
        grid[i][j] = 1
        dfs(grid, i - 1, j)
        dfs(grid, i + 1, j)
        dfs(grid, i, j - 1)
        dfs(grid, i, j + 1)
    }

}

Compiled from "P959.kt"
public final class com.leetcode.P959 {
  public com.leetcode.P959();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int regionsBySlashes(java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String grid
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: arraylength
       8: istore_2
       9: iconst_0
      10: istore        4
      12: iload_2
      13: iconst_3
      14: imul
      15: istore        5
      17: iload         5
      19: anewarray     #23                 // class "[I"
      22: astore        6
      24: iload         4
      26: iload         5
      28: if_icmpge     51
      31: iload         4
      33: istore        7
      35: aload         6
      37: iload         7
      39: iload_2
      40: iconst_3
      41: imul
      42: newarray       int
      44: aastore
      45: iinc          4, 1
      48: goto          24
      51: aload         6
      53: astore_3
      54: iconst_0
      55: istore        4
      57: iload_2
      58: iload_2
      59: imul
      60: istore        5
      62: iload         4
      64: iload         5
      66: if_icmpge     233
      69: iconst_2
      70: newarray       int
      72: astore        7
      74: aload         7
      76: iconst_0
      77: iload         4
      79: iload_2
      80: idiv
      81: iconst_3
      82: imul
      83: iastore
      84: aload         7
      86: iconst_1
      87: iload         4
      89: iload_2
      90: irem
      91: iconst_3
      92: imul
      93: iastore
      94: aload         7
      96: astore        6
      98: aload_1
      99: iload         4
     101: iload_2
     102: idiv
     103: aaload
     104: iload         4
     106: iload_2
     107: irem
     108: invokevirtual #29                 // Method java/lang/String.charAt:(I)C
     111: lookupswitch  { // 2
                    47: 183
                    92: 136
               default: 227
          }
     136: aload_3
     137: aload         6
     139: iconst_0
     140: iaload
     141: aaload
     142: aload         6
     144: iconst_1
     145: iaload
     146: iconst_1
     147: iastore
     148: aload_3
     149: aload         6
     151: iconst_0
     152: iaload
     153: iconst_1
     154: iadd
     155: aaload
     156: aload         6
     158: iconst_1
     159: iaload
     160: iconst_1
     161: iadd
     162: iconst_1
     163: iastore
     164: aload_3
     165: aload         6
     167: iconst_0
     168: iaload
     169: iconst_2
     170: iadd
     171: aaload
     172: aload         6
     174: iconst_1
     175: iaload
     176: iconst_2
     177: iadd
     178: iconst_1
     179: iastore
     180: goto          227
     183: aload_3
     184: aload         6
     186: iconst_0
     187: iaload
     188: aaload
     189: aload         6
     191: iconst_1
     192: iaload
     193: iconst_2
     194: iadd
     195: iconst_1
     196: iastore
     197: aload_3
     198: aload         6
     200: iconst_0
     201: iaload
     202: iconst_1
     203: iadd
     204: aaload
     205: aload         6
     207: iconst_1
     208: iaload
     209: iconst_1
     210: iadd
     211: iconst_1
     212: iastore
     213: aload_3
     214: aload         6
     216: iconst_0
     217: iaload
     218: iconst_2
     219: iadd
     220: aaload
     221: aload         6
     223: iconst_1
     224: iaload
     225: iconst_1
     226: iastore
     227: iinc          4, 1
     230: goto          62
     233: iconst_0
     234: istore        4
     236: iconst_0
     237: istore        5
     239: aload_3
     240: checkcast     #31                 // class "[Ljava/lang/Object;"
     243: arraylength
     244: istore        6
     246: iload         5
     248: iload         6
     250: if_icmpge     304
     253: iconst_0
     254: istore        7
     256: aload_3
     257: iload         5
     259: aaload
     260: arraylength
     261: istore        8
     263: iload         7
     265: iload         8
     267: if_icmpge     298
     270: aload_3
     271: iload         5
     273: aaload
     274: iload         7
     276: iaload
     277: ifne          292
     280: aload_0
     281: aload_3
     282: iload         5
     284: iload         7
     286: invokespecial #35                 // Method dfs:([[III)V
     289: iinc          4, 1
     292: iinc          7, 1
     295: goto          263
     298: iinc          5, 1
     301: goto          246
     304: iload         4
     306: ireturn

  private final void dfs(int[][], int, int);
    Code:
       0: iconst_0
       1: iload_2
       2: if_icmpgt     24
       5: iload_2
       6: aload_1
       7: checkcast     #31                 // class "[Ljava/lang/Object;"
      10: invokestatic  #52                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
      13: if_icmpgt     20
      16: iconst_1
      17: goto          25
      20: iconst_0
      21: goto          25
      24: iconst_0
      25: ifne          29
      28: return
      29: iconst_0
      30: iload_3
      31: if_icmpgt     52
      34: iload_3
      35: aload_1
      36: iload_2
      37: aaload
      38: invokestatic  #55                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      41: if_icmpgt     48
      44: iconst_1
      45: goto          53
      48: iconst_0
      49: goto          53
      52: iconst_0
      53: ifne          57
      56: return
      57: aload_1
      58: iload_2
      59: aaload
      60: iload_3
      61: iaload
      62: iconst_1
      63: if_icmpne     67
      66: return
      67: aload_1
      68: iload_2
      69: aaload
      70: iload_3
      71: iconst_1
      72: iastore
      73: aload_0
      74: aload_1
      75: iload_2
      76: iconst_1
      77: isub
      78: iload_3
      79: invokespecial #35                 // Method dfs:([[III)V
      82: aload_0
      83: aload_1
      84: iload_2
      85: iconst_1
      86: iadd
      87: iload_3
      88: invokespecial #35                 // Method dfs:([[III)V
      91: aload_0
      92: aload_1
      93: iload_2
      94: iload_3
      95: iconst_1
      96: isub
      97: invokespecial #35                 // Method dfs:([[III)V
     100: aload_0
     101: aload_1
     102: iload_2
     103: iload_3
     104: iconst_1
     105: iadd
     106: invokespecial #35                 // Method dfs:([[III)V
     109: return
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/467
class P980 {
    fun uniquePathsIII(grid: Array<IntArray>): Int {
        var y = 0
        var x = 0
        var total = 0 // 갈 수 있는 남은 칸 수
        for (i in grid.indices) {
            for (j in grid[i].indices) {
                val v = grid[i][j]
                if (v == 0) { // 이동 가능 칸
                    total++
                } else if (v == 1) { // 출발 칸
                    y = i
                    x = j
                    // 시작 지점을 갈 수 있는 블럭으로 처리
                    grid[y][x] = 0
                    total++
                }
            }
        }
        return dfs(grid, y, x, total)
    }

    private fun dfs(grid: Array<IntArray>, y: Int, x: Int, remain: Int): Int {
        if (y < 0 || y >= grid.size
            || x < 0 || x >= grid[y].size
            || grid[y][x] == -1 // 벽
        ) {
            return 0
        }
        // 도착
        if (grid[y][x] == 2) {
            // 남아있는 칸이 없어야 함
            return if (remain == 0) 1 else 0
        }
        grid[y][x] = -1 // visited
        val r = remain - 1
        val sum = dfs(grid, y - 1, x, r) + // 북
                dfs(grid, y, x + 1, r) + // 동
                dfs(grid, y + 1, x, r) + // 남
                dfs(grid, y, x - 1, r) // 서
        grid[y][x] = 0 // backtracking
        return sum
    }

}

Compiled from "P980.kt"
public final class com.leetcode.P980 {
  public com.leetcode.P980();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int uniquePathsIII(int[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String grid
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: iconst_0
      11: istore        4
      13: iconst_0
      14: istore        5
      16: aload_1
      17: checkcast     #23                 // class "[Ljava/lang/Object;"
      20: arraylength
      21: istore        6
      23: iload         5
      25: iload         6
      27: if_icmpge     113
      30: iconst_0
      31: istore        7
      33: aload_1
      34: iload         5
      36: aaload
      37: arraylength
      38: istore        8
      40: iload         7
      42: iload         8
      44: if_icmpge     107
      47: aload_1
      48: iload         5
      50: aaload
      51: iload         7
      53: iaload
      54: istore        9
      56: iload         9
      58: tableswitch   { // 0 to 1
                     0: 80
                     1: 86
               default: 101
          }
      80: iinc          4, 1
      83: goto          101
      86: iload         5
      88: istore_2
      89: iload         7
      91: istore_3
      92: aload_1
      93: iload_2
      94: aaload
      95: iload_3
      96: iconst_0
      97: iastore
      98: iinc          4, 1
     101: iinc          7, 1
     104: goto          40
     107: iinc          5, 1
     110: goto          23
     113: aload_0
     114: aload_1
     115: iload_2
     116: iload_3
     117: iload         4
     119: invokespecial #27                 // Method dfs:([[IIII)I
     122: ireturn

  private final int dfs(int[][], int, int, int);
    Code:
       0: iload_2
       1: iflt          34
       4: iload_2
       5: aload_1
       6: checkcast     #23                 // class "[Ljava/lang/Object;"
       9: arraylength
      10: if_icmpge     34
      13: iload_3
      14: iflt          34
      17: iload_3
      18: aload_1
      19: iload_2
      20: aaload
      21: arraylength
      22: if_icmpge     34
      25: aload_1
      26: iload_2
      27: aaload
      28: iload_3
      29: iaload
      30: iconst_m1
      31: if_icmpne     36
      34: iconst_0
      35: ireturn
      36: aload_1
      37: iload_2
      38: aaload
      39: iload_3
      40: iaload
      41: iconst_2
      42: if_icmpne     56
      45: iload         4
      47: ifne          54
      50: iconst_1
      51: goto          55
      54: iconst_0
      55: ireturn
      56: aload_1
      57: iload_2
      58: aaload
      59: iload_3
      60: iconst_m1
      61: iastore
      62: iload         4
      64: iconst_1
      65: isub
      66: istore        5
      68: aload_0
      69: aload_1
      70: iload_2
      71: iconst_1
      72: isub
      73: iload_3
      74: iload         5
      76: invokespecial #27                 // Method dfs:([[IIII)I
      79: aload_0
      80: aload_1
      81: iload_2
      82: iload_3
      83: iconst_1
      84: iadd
      85: iload         5
      87: invokespecial #27                 // Method dfs:([[IIII)I
      90: iadd
      91: aload_0
      92: aload_1
      93: iload_2
      94: iconst_1
      95: iadd
      96: iload_3
      97: iload         5
      99: invokespecial #27                 // Method dfs:([[IIII)I
     102: iadd
     103: aload_0
     104: aload_1
     105: iload_2
     106: iload_3
     107: iconst_1
     108: isub
     109: iload         5
     111: invokespecial #27                 // Method dfs:([[IIII)I
     114: iadd
     115: istore        6
     117: aload_1
     118: iload_2
     119: aaload
     120: iload_3
     121: iconst_0
     122: iastore
     123: iload         6
     125: ireturn
}


package com.leetcode

// https://leetcode.com/problems/different-ways-to-add-parentheses/
class P241 {
    private val ops = setOf('+', '-', '*')

    fun diffWaysToCompute(expression: String): List<Int> {
        val values = mutableListOf<Int>()
        // 연산자를 만나면 왼쪽 계산식과 오른쪽 계산식을 나눠서 재귀
        expression.forEachIndexed { i, ch ->
            if (ch in ops) {
                val left = diffWaysToCompute(expression.substring(0, i))
                val right = diffWaysToCompute(expression.substring(i + 1))
                values += merge(left, right, ch)
            }
        }
        // 연산자가 없고 숫자만 있을 경우
        if (values.isEmpty()) {
            values += expression.toInt()
        }
        return values
    }

    private fun merge(left: List<Int>, right: List<Int>, op: Char) = mutableListOf<Int>().apply {
        for (l in left) {
            for (r in right) {
                when (op) {
                    '+' -> this += l + r
                    '-' -> this += l - r
                    '*' -> this += l * r
                }
            }
        }
    }

}

Compiled from "P241.kt"
public final class com.leetcode.P241 {
  private final java.util.Set<java.lang.Character> ops;

  public com.leetcode.P241();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iconst_3
       6: anewarray     #10                 // class java/lang/Character
       9: astore_1
      10: aload_1
      11: iconst_0
      12: bipush        43
      14: invokestatic  #14                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      17: aastore
      18: aload_1
      19: iconst_1
      20: bipush        45
      22: invokestatic  #14                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      25: aastore
      26: aload_1
      27: iconst_2
      28: bipush        42
      30: invokestatic  #14                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      33: aastore
      34: aload_1
      35: invokestatic  #20                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      38: putfield      #24                 // Field ops:Ljava/util/Set;
      41: return

  public final java.util.List<java.lang.Integer> diffWaysToCompute(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #32                 // String expression
       3: invokestatic  #38                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #40                 // class java/util/ArrayList
       9: dup
      10: invokespecial #41                 // Method java/util/ArrayList."<init>":()V
      13: checkcast     #43                 // class java/util/List
      16: astore_2
      17: aload_1
      18: checkcast     #45                 // class java/lang/CharSequence
      21: astore_3
      22: iconst_0
      23: istore        4
      25: iconst_0
      26: istore        5
      28: iconst_0
      29: istore        6
      31: iload         6
      33: aload_3
      34: invokeinterface #49,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      39: if_icmpge     151
      42: aload_3
      43: iload         6
      45: invokeinterface #53,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      50: istore        7
      52: iload         5
      54: iinc          5, 1
      57: iload         7
      59: istore        8
      61: istore        9
      63: iconst_0
      64: istore        10
      66: aload_0
      67: getfield      #24                 // Field ops:Ljava/util/Set;
      70: iload         8
      72: invokestatic  #14                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      75: invokeinterface #59,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      80: ifeq          143
      83: aload_0
      84: aload_1
      85: iconst_0
      86: iload         9
      88: invokevirtual #65                 // Method java/lang/String.substring:(II)Ljava/lang/String;
      91: dup
      92: ldc           #67                 // String substring(...)
      94: invokestatic  #70                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      97: invokevirtual #72                 // Method diffWaysToCompute:(Ljava/lang/String;)Ljava/util/List;
     100: astore        11
     102: aload_0
     103: aload_1
     104: iload         9
     106: iconst_1
     107: iadd
     108: invokevirtual #75                 // Method java/lang/String.substring:(I)Ljava/lang/String;
     111: dup
     112: ldc           #67                 // String substring(...)
     114: invokestatic  #70                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     117: invokevirtual #72                 // Method diffWaysToCompute:(Ljava/lang/String;)Ljava/util/List;
     120: astore        12
     122: aload_2
     123: checkcast     #77                 // class java/util/Collection
     126: aload_0
     127: aload         11
     129: aload         12
     131: iload         8
     133: invokespecial #81                 // Method merge:(Ljava/util/List;Ljava/util/List;C)Ljava/util/List;
     136: checkcast     #83                 // class java/lang/Iterable
     139: invokestatic  #89                 // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     142: pop
     143: nop
     144: nop
     145: iinc          6, 1
     148: goto          31
     151: nop
     152: aload_2
     153: invokeinterface #93,  1           // InterfaceMethod java/util/List.isEmpty:()Z
     158: ifeq          179
     161: nop
     162: aload_2
     163: checkcast     #77                 // class java/util/Collection
     166: aload_1
     167: invokestatic  #99                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     170: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     173: invokeinterface #105,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     178: pop
     179: aload_2
     180: areturn

  private final java.util.List<java.lang.Integer> merge(java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>, char);
    Code:
       0: new           #40                 // class java/util/ArrayList
       3: dup
       4: invokespecial #41                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #43                 // class java/util/List
      10: astore        4
      12: aload         4
      14: astore        5
      16: iconst_0
      17: istore        6
      19: aload_1
      20: invokeinterface #125,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      25: astore        7
      27: aload         7
      29: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifeq          182
      37: aload         7
      39: invokeinterface #134,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      44: checkcast     #136                // class java/lang/Number
      47: invokevirtual #139                // Method java/lang/Number.intValue:()I
      50: istore        8
      52: aload_2
      53: invokeinterface #125,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      58: astore        9
      60: aload         9
      62: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          27
      70: aload         9
      72: invokeinterface #134,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: checkcast     #136                // class java/lang/Number
      80: invokevirtual #139                // Method java/lang/Number.intValue:()I
      83: istore        10
      85: iload_3
      86: tableswitch   { // 42 to 45
                    42: 160
                    43: 116
                    44: 179
                    45: 138
               default: 179
          }
     116: aload         5
     118: checkcast     #77                 // class java/util/Collection
     121: iload         8
     123: iload         10
     125: iadd
     126: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     129: invokeinterface #105,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     134: pop
     135: goto          60
     138: aload         5
     140: checkcast     #77                 // class java/util/Collection
     143: iload         8
     145: iload         10
     147: isub
     148: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     151: invokeinterface #105,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     156: pop
     157: goto          60
     160: aload         5
     162: checkcast     #77                 // class java/util/Collection
     165: iload         8
     167: iload         10
     169: imul
     170: invokestatic  #102                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     173: invokeinterface #105,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     178: pop
     179: goto          60
     182: nop
     183: aload         4
     185: areturn
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/459
class P37 {
    fun solveSudoku(board: Array<CharArray>) {
        solve(board, 0)
    }

    private fun solve(board: Array<CharArray>, pos: Int): Boolean {
        if (pos == 81) {
            return true
        }
        val y = pos / 9
        val x = pos % 9

        val set = possible(board, y, x)
        if (set.isEmpty()) {
            return false
        }

        val before = board[y][x]
        for (ch in set) {
            board[y][x] = ch
            val bool = solve(board, pos + 1)
            if (bool) return true
        }

        board[y][x] = before // backtracking
        return false
    }

    private fun possible(board: Array<CharArray>, y: Int, x: Int): Set<Char> {
        if (board[y][x] != '.') {
            return setOf(board[y][x])
        }

        val set = mutableSetOf('1', '2', '3', '4', '5', '6', '7', '8', '9')
        // 나와 같은 행의 수 제거
        for (i in 0 until 9) {
            val ch = board[i][x]
            if (ch != '0') {
                set -= ch
            }
        }
        // 나와 같은 열의 수 제거
        for (i in 0 until 9) {
            val ch = board[y][i]
            if (ch != '.') {
                set -= ch
            }
        }
        // 나와 같은 칸의 수 제거
        val startY = (y / 3) * 3
        val startX = (x / 3) * 3
        for (i in startY until startY + 3) {
            for (j in startX until startX + 3) {
                val ch = board[i][j]
                if (ch != '.') {
                    set -= ch
                }
            }
        }
        return set
    }

}

Compiled from "P37.kt"
public final class com.leetcode.P37 {
  public com.leetcode.P37();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void solveSudoku(char[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String board
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: iconst_0
       9: invokespecial #25                 // Method solve:([[CI)Z
      12: pop
      13: return

  private final boolean solve(char[][], int);
    Code:
       0: iload_2
       1: bipush        81
       3: if_icmpne     8
       6: iconst_1
       7: ireturn
       8: iload_2
       9: bipush        9
      11: idiv
      12: istore_3
      13: iload_2
      14: bipush        9
      16: irem
      17: istore        4
      19: aload_0
      20: aload_1
      21: iload_3
      22: iload         4
      24: invokespecial #30                 // Method possible:([[CII)Ljava/util/Set;
      27: astore        5
      29: aload         5
      31: invokeinterface #36,  1           // InterfaceMethod java/util/Set.isEmpty:()Z
      36: ifeq          41
      39: iconst_0
      40: ireturn
      41: aload_1
      42: iload_3
      43: aaload
      44: iload         4
      46: caload
      47: istore        6
      49: aload         5
      51: invokeinterface #40,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      56: astore        7
      58: aload         7
      60: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          108
      68: aload         7
      70: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: checkcast     #51                 // class java/lang/Character
      78: invokevirtual #55                 // Method java/lang/Character.charValue:()C
      81: istore        8
      83: aload_1
      84: iload_3
      85: aaload
      86: iload         4
      88: iload         8
      90: castore
      91: aload_0
      92: aload_1
      93: iload_2
      94: iconst_1
      95: iadd
      96: invokespecial #25                 // Method solve:([[CI)Z
      99: istore        9
     101: iload         9
     103: ifeq          58
     106: iconst_1
     107: ireturn
     108: aload_1
     109: iload_3
     110: aaload
     111: iload         4
     113: iload         6
     115: castore
     116: iconst_0
     117: ireturn

  private final java.util.Set<java.lang.Character> possible(char[][], int, int);
    Code:
       0: aload_1
       1: iload_2
       2: aaload
       3: iload_3
       4: caload
       5: bipush        46
       7: if_icmpeq     22
      10: aload_1
      11: iload_2
      12: aaload
      13: iload_3
      14: caload
      15: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      18: invokestatic  #77                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      21: areturn
      22: bipush        9
      24: anewarray     #51                 // class java/lang/Character
      27: astore        5
      29: aload         5
      31: iconst_0
      32: bipush        49
      34: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      37: aastore
      38: aload         5
      40: iconst_1
      41: bipush        50
      43: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      46: aastore
      47: aload         5
      49: iconst_2
      50: bipush        51
      52: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      55: aastore
      56: aload         5
      58: iconst_3
      59: bipush        52
      61: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      64: aastore
      65: aload         5
      67: iconst_4
      68: bipush        53
      70: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      73: aastore
      74: aload         5
      76: iconst_5
      77: bipush        54
      79: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      82: aastore
      83: aload         5
      85: bipush        6
      87: bipush        55
      89: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      92: aastore
      93: aload         5
      95: bipush        7
      97: bipush        56
      99: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     102: aastore
     103: aload         5
     105: bipush        8
     107: bipush        57
     109: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     112: aastore
     113: aload         5
     115: invokestatic  #81                 // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
     118: astore        4
     120: iconst_0
     121: istore        5
     123: iload         5
     125: bipush        9
     127: if_icmpge     171
     130: aload_1
     131: iload         5
     133: aaload
     134: iload_3
     135: caload
     136: istore        6
     138: iload         6
     140: bipush        48
     142: if_icmpeq     165
     145: iload         6
     147: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     150: astore        8
     152: aload         4
     154: checkcast     #83                 // class java/util/Collection
     157: aload         8
     159: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.remove:(Ljava/lang/Object;)Z
     164: pop
     165: iinc          5, 1
     168: goto          123
     171: iconst_0
     172: istore        5
     174: iload         5
     176: bipush        9
     178: if_icmpge     222
     181: aload_1
     182: iload_2
     183: aaload
     184: iload         5
     186: caload
     187: istore        6
     189: iload         6
     191: bipush        46
     193: if_icmpeq     216
     196: iload         6
     198: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     201: astore        8
     203: aload         4
     205: checkcast     #83                 // class java/util/Collection
     208: aload         8
     210: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.remove:(Ljava/lang/Object;)Z
     215: pop
     216: iinc          5, 1
     219: goto          174
     222: iload_2
     223: iconst_3
     224: idiv
     225: iconst_3
     226: imul
     227: istore        5
     229: iload_3
     230: iconst_3
     231: idiv
     232: iconst_3
     233: imul
     234: istore        6
     236: iload         5
     238: istore        7
     240: iload         5
     242: iconst_3
     243: iadd
     244: istore        8
     246: iload         7
     248: iload         8
     250: if_icmpge     318
     253: iload         6
     255: istore        9
     257: iload         6
     259: iconst_3
     260: iadd
     261: istore        10
     263: iload         9
     265: iload         10
     267: if_icmpge     312
     270: aload_1
     271: iload         7
     273: aaload
     274: iload         9
     276: caload
     277: istore        11
     279: iload         11
     281: bipush        46
     283: if_icmpeq     306
     286: iload         11
     288: invokestatic  #71                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     291: astore        12
     293: aload         4
     295: checkcast     #83                 // class java/util/Collection
     298: aload         12
     300: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.remove:(Ljava/lang/Object;)Z
     305: pop
     306: iinc          9, 1
     309: goto          263
     312: iinc          7, 1
     315: goto          246
     318: aload         4
     320: areturn
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/494
class P473 {
    fun makesquare(matchsticks: IntArray): Boolean {
        val sum = matchsticks.sum()
        // 모든 성냥의 길이가 4면으로 떨어지지 않으면 안됨
        if (sum % 4 > 0) return false
        val length = sum / 4
        // 길이가 긴 성냥순으로 정렬
        matchsticks.sortDescending()
        // 가장 긴 성냥의 길이가 한면의 길이보다 크면 안됨
        if (matchsticks[0] > length) return false
        // 4면
        val square = IntArray(4) { length }
        // DFS 탐색
        return dfs(matchsticks, 0, square)
    }

    private fun dfs(matchsticks: IntArray, i: Int, square: IntArray): Boolean {
        // 성냥을 모두 사용했을 때 4면을 전부 채웠는지 체크
        if (i >= matchsticks.size) {
            return square.all { it == 0 }
        }
        // 현재 성냥을 어느 면에 넣을지 선택
        for (j in square.indices) {
            if (square[j] >= matchsticks[i]) {
                square[j] -= matchsticks[i]
                if (dfs(matchsticks, i + 1, square)) {
                    return true
                }
                square[j] += matchsticks[i] // backtracking
            }
        }
        // 현재 성냥을 어느 면에도 넣지 못했으면 안됨
        return false
    }
}

Compiled from "P473.kt"
public final class com.leetcode.P473 {
  public com.leetcode.P473();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final boolean makesquare(int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String matchsticks
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #27                 // Method kotlin/collections/ArraysKt.sum:([I)I
      10: istore_2
      11: iload_2
      12: iconst_4
      13: irem
      14: ifle          19
      17: iconst_0
      18: ireturn
      19: iload_2
      20: iconst_4
      21: idiv
      22: istore_3
      23: aload_1
      24: invokestatic  #31                 // Method kotlin/collections/ArraysKt.sortDescending:([I)V
      27: aload_1
      28: iconst_0
      29: iaload
      30: iload_3
      31: if_icmple     36
      34: iconst_0
      35: ireturn
      36: iconst_0
      37: istore        5
      39: iconst_4
      40: newarray       int
      42: astore        6
      44: iload         5
      46: iconst_4
      47: if_icmpge     66
      50: iload         5
      52: istore        7
      54: aload         6
      56: iload         7
      58: iload_3
      59: iastore
      60: iinc          5, 1
      63: goto          44
      66: aload         6
      68: astore        4
      70: aload_0
      71: aload_1
      72: iconst_0
      73: aload         4
      75: invokespecial #35                 // Method dfs:([II[I)Z
      78: ireturn

  private final boolean dfs(int[], int, int[]);
    Code:
       0: iload_2
       1: aload_1
       2: arraylength
       3: if_icmplt     66
       6: aload_3
       7: astore        4
       9: iconst_0
      10: istore        5
      12: iconst_0
      13: istore        6
      15: aload         4
      17: arraylength
      18: istore        7
      20: iload         6
      22: iload         7
      24: if_icmpge     64
      27: aload         4
      29: iload         6
      31: iaload
      32: istore        8
      34: iload         8
      36: istore        9
      38: iconst_0
      39: istore        10
      41: iload         9
      43: ifne          50
      46: iconst_1
      47: goto          51
      50: iconst_0
      51: ifne          58
      54: iconst_0
      55: goto          65
      58: iinc          6, 1
      61: goto          20
      64: iconst_1
      65: ireturn
      66: iconst_0
      67: istore        4
      69: aload_3
      70: arraylength
      71: istore        5
      73: iload         4
      75: iload         5
      77: if_icmpge     142
      80: aload_3
      81: iload         4
      83: iaload
      84: aload_1
      85: iload_2
      86: iaload
      87: if_icmplt     136
      90: iload         4
      92: istore        6
      94: aload_3
      95: iload         6
      97: aload_3
      98: iload         6
     100: iaload
     101: aload_1
     102: iload_2
     103: iaload
     104: isub
     105: iastore
     106: aload_0
     107: aload_1
     108: iload_2
     109: iconst_1
     110: iadd
     111: aload_3
     112: invokespecial #35                 // Method dfs:([II[I)Z
     115: ifeq          120
     118: iconst_1
     119: ireturn
     120: iload         4
     122: istore        6
     124: aload_3
     125: iload         6
     127: aload_3
     128: iload         6
     130: iaload
     131: aload_1
     132: iload_2
     133: iaload
     134: iadd
     135: iastore
     136: iinc          4, 1
     139: goto          73
     142: iconst_0
     143: ireturn
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/331
class P93 {
    val answer = mutableListOf<String>()

    fun restoreIpAddresses(s: String): List<String> {
        if (s.length !in 4..12) return listOf()
        dfs(s, 0, 0, StringBuffer())
        return answer
    }

    /**
     * @param s 원본 문자열
     * @param i 문자열의 현재 인덱스
     * @param dots 사용된 쩜(".")의 개수
     * @param ip 만들어가고 있는 문자열
     */
    fun dfs(s: String, i: Int, dots: Int, ip: StringBuffer) {
        // 쩜을 다 사용했지만 문자열을 다 소비 못한 경우
        if (dots > 3 && i < s.length) {
            return
        }

        if (i == s.length && dots > 3) { // 완성
            answer += ip.toString()
            return
        }

        val prevLength = ip.length // 백트래킹할 이전 문자열 길이
        if (i > 0) ip.append(".") // 쩜이 한번 사용됨

        var num = 0
        // 한자리, 두자리, 세자리 계산
        val maxIndex = minOf(s.lastIndex - (3 - dots), i + 2)
        for (j in i..maxIndex) {
            val c = s[j]

            // IP는 0 ~ 225만 허용된다.
            num = (num * 10) + (c - '0')
            if (num > 255) break

            ip.append(c)
            dfs(s, j + 1, dots + 1, ip)

            // IP의 첫자리가 0이면 두세번째 자리는 패스
            if (num == 0) break
        }
        // 백트래킹
        ip.setLength(prevLength)
    }

}

Compiled from "P93.kt"
public final class com.leetcode.P93 {
  private final java.util.List<java.lang.String> answer;

  public com.leetcode.P93();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: new           #10                 // class java/util/ArrayList
       8: dup
       9: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      12: checkcast     #13                 // class java/util/List
      15: putfield      #17                 // Field answer:Ljava/util/List;
      18: return

  public final java.util.List<java.lang.String> getAnswer();
    Code:
       0: aload_0
       1: getfield      #17                 // Field answer:Ljava/util/List;
       4: areturn

  public final java.util.List<java.lang.String> restoreIpAddresses(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #28                 // String s
       3: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokevirtual #40                 // Method java/lang/String.length:()I
      10: istore_2
      11: iconst_4
      12: iload_2
      13: if_icmpgt     30
      16: iload_2
      17: bipush        13
      19: if_icmpge     26
      22: iconst_1
      23: goto          31
      26: iconst_0
      27: goto          31
      30: iconst_0
      31: ifne          38
      34: invokestatic  #45                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      37: areturn
      38: aload_0
      39: aload_1
      40: iconst_0
      41: iconst_0
      42: new           #47                 // class java/lang/StringBuffer
      45: dup
      46: invokespecial #48                 // Method java/lang/StringBuffer."<init>":()V
      49: invokevirtual #52                 // Method dfs:(Ljava/lang/String;IILjava/lang/StringBuffer;)V
      52: aload_0
      53: getfield      #17                 // Field answer:Ljava/util/List;
      56: areturn

  public final void dfs(java.lang.String, int, int, java.lang.StringBuffer);
    Code:
       0: aload_1
       1: ldc           #28                 // String s
       3: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload         4
       8: ldc           #55                 // String ip
      10: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: iload_3
      14: iconst_3
      15: if_icmple     27
      18: iload_2
      19: aload_1
      20: invokevirtual #40                 // Method java/lang/String.length:()I
      23: if_icmpge     27
      26: return
      27: iload_2
      28: aload_1
      29: invokevirtual #40                 // Method java/lang/String.length:()I
      32: if_icmpne     59
      35: iload_3
      36: iconst_3
      37: if_icmple     59
      40: aload_0
      41: getfield      #17                 // Field answer:Ljava/util/List;
      44: checkcast     #57                 // class java/util/Collection
      47: aload         4
      49: invokevirtual #61                 // Method java/lang/StringBuffer.toString:()Ljava/lang/String;
      52: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      57: pop
      58: return
      59: aload         4
      61: invokevirtual #66                 // Method java/lang/StringBuffer.length:()I
      64: istore        5
      66: iload_2
      67: ifle          78
      70: aload         4
      72: ldc           #68                 // String .
      74: invokevirtual #72                 // Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
      77: pop
      78: iconst_0
      79: istore        6
      81: aload_1
      82: checkcast     #74                 // class java/lang/CharSequence
      85: invokestatic  #80                 // Method kotlin/text/StringsKt.getLastIndex:(Ljava/lang/CharSequence;)I
      88: iconst_3
      89: iload_3
      90: isub
      91: isub
      92: iload_2
      93: iconst_2
      94: iadd
      95: invokestatic  #86                 // Method java/lang/Math.min:(II)I
      98: istore        7
     100: iload_2
     101: istore        8
     103: iload         8
     105: iload         7
     107: if_icmpgt     179
     110: aload_1
     111: iload         8
     113: invokevirtual #90                 // Method java/lang/String.charAt:(I)C
     116: istore        9
     118: iload         6
     120: bipush        10
     122: imul
     123: iload         9
     125: bipush        48
     127: isub
     128: iadd
     129: istore        6
     131: iload         6
     133: sipush        255
     136: if_icmpgt     179
     139: aload         4
     141: iload         9
     143: invokevirtual #93                 // Method java/lang/StringBuffer.append:(C)Ljava/lang/StringBuffer;
     146: pop
     147: aload_0
     148: aload_1
     149: iload         8
     151: iconst_1
     152: iadd
     153: iload_3
     154: iconst_1
     155: iadd
     156: aload         4
     158: invokevirtual #52                 // Method dfs:(Ljava/lang/String;IILjava/lang/StringBuffer;)V
     161: iload         6
     163: ifeq          179
     166: iload         8
     168: iload         7
     170: if_icmpeq     179
     173: iinc          8, 1
     176: goto          110
     179: aload         4
     181: iload         5
     183: invokevirtual #97                 // Method java/lang/StringBuffer.setLength:(I)V
     186: return
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/280
class P48 {
    fun rotate(matrix: Array<IntArray>) {
        var p = 0
        var length = matrix.size
        while (length > 1) {
            rotate(matrix, p++, length)
            length -= 2
        }
    }

    private fun rotate(matrix: Array<IntArray>, p: Int, length: Int) {
        if (length == 1) return

        val max = p + length - 1
        val list = mutableListOf<Int>()

        for (i in p until p + length) list += matrix[p][i] // 1
        for (i in p + 1 until p + length) list += matrix[i][max] // 2
        for (i in p + length - 2 downTo p) list += matrix[max][i] // 3
        for (i in p + length - 2 downTo p + 1) list += matrix[i][p] // 4

        repeat(length - 1) {
            list.add(0, list.removeAt(list.lastIndex))
        }

        var k = 0
        for (i in p until p + length) matrix[p][i] = list[k++]
        for (i in p + 1 until p + length) matrix[i][max] = list[k++]
        for (i in p + length - 2 downTo p) matrix[max][i] = list[k++]
        for (i in p + length - 2 downTo p + 1) matrix[i][p] = list[k++]
    }

}

Compiled from "P48.kt"
public final class com.leetcode.P48 {
  public com.leetcode.P48();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void rotate(int[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String matrix
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_1
       9: checkcast     #23                 // class "[Ljava/lang/Object;"
      12: arraylength
      13: istore_3
      14: iload_3
      15: iconst_1
      16: if_icmple     35
      19: aload_0
      20: aload_1
      21: iload_2
      22: iinc          2, 1
      25: iload_3
      26: invokespecial #26                 // Method rotate:([[III)V
      29: iinc          3, -2
      32: goto          14
      35: return

  private final void rotate(int[][], int, int);
    Code:
       0: iload_3
       1: iconst_1
       2: if_icmpne     6
       5: return
       6: iload_2
       7: iload_3
       8: iadd
       9: iconst_1
      10: isub
      11: istore        4
      13: new           #32                 // class java/util/ArrayList
      16: dup
      17: invokespecial #33                 // Method java/util/ArrayList."<init>":()V
      20: checkcast     #35                 // class java/util/List
      23: astore        5
      25: iload_2
      26: istore        6
      28: iload_2
      29: iload_3
      30: iadd
      31: istore        7
      33: iload         6
      35: iload         7
      37: if_icmpge     66
      40: aload         5
      42: checkcast     #37                 // class java/util/Collection
      45: aload_1
      46: iload_2
      47: aaload
      48: iload         6
      50: iaload
      51: invokestatic  #43                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: invokeinterface #47,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      59: pop
      60: iinc          6, 1
      63: goto          33
      66: iload_2
      67: iconst_1
      68: iadd
      69: istore        6
      71: iload_2
      72: iload_3
      73: iadd
      74: istore        7
      76: iload         6
      78: iload         7
      80: if_icmpge     110
      83: aload         5
      85: checkcast     #37                 // class java/util/Collection
      88: aload_1
      89: iload         6
      91: aaload
      92: iload         4
      94: iaload
      95: invokestatic  #43                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      98: invokeinterface #47,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     103: pop
     104: iinc          6, 1
     107: goto          76
     110: iload_2
     111: iload_3
     112: iadd
     113: iconst_2
     114: isub
     115: istore        6
     117: iload_2
     118: iload         6
     120: if_icmpgt     156
     123: aload         5
     125: checkcast     #37                 // class java/util/Collection
     128: aload_1
     129: iload         4
     131: aaload
     132: iload         6
     134: iaload
     135: invokestatic  #43                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: invokeinterface #47,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     143: pop
     144: iload         6
     146: iload_2
     147: if_icmpeq     156
     150: iinc          6, -1
     153: goto          123
     156: iload_2
     157: iload_3
     158: iadd
     159: iconst_2
     160: isub
     161: istore        6
     163: iload_2
     164: iconst_1
     165: iadd
     166: istore        7
     168: iload         7
     170: iload         6
     172: if_icmpgt     208
     175: aload         5
     177: checkcast     #37                 // class java/util/Collection
     180: aload_1
     181: iload         6
     183: aaload
     184: iload_2
     185: iaload
     186: invokestatic  #43                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     189: invokeinterface #47,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     194: pop
     195: iload         6
     197: iload         7
     199: if_icmpeq     208
     202: iinc          6, -1
     205: goto          175
     208: iload_3
     209: iconst_1
     210: isub
     211: istore        6
     213: iconst_0
     214: istore        7
     216: iload         7
     218: iload         6
     220: if_icmpge     257
     223: iload         7
     225: istore        8
     227: iconst_0
     228: istore        9
     230: aload         5
     232: iconst_0
     233: aload         5
     235: aload         5
     237: invokestatic  #53                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     240: invokeinterface #57,  2           // InterfaceMethod java/util/List.remove:(I)Ljava/lang/Object;
     245: invokeinterface #60,  3           // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
     250: nop
     251: iinc          7, 1
     254: goto          216
     257: iconst_0
     258: istore        6
     260: iload_2
     261: istore        7
     263: iload_2
     264: iload_3
     265: iadd
     266: istore        8
     268: iload         7
     270: iload         8
     272: if_icmpge     305
     275: aload_1
     276: iload_2
     277: aaload
     278: iload         7
     280: aload         5
     282: iload         6
     284: iinc          6, 1
     287: invokeinterface #63,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     292: checkcast     #65                 // class java/lang/Number
     295: invokevirtual #69                 // Method java/lang/Number.intValue:()I
     298: iastore
     299: iinc          7, 1
     302: goto          268
     305: iload_2
     306: iconst_1
     307: iadd
     308: istore        7
     310: iload_2
     311: iload_3
     312: iadd
     313: istore        8
     315: iload         7
     317: iload         8
     319: if_icmpge     353
     322: aload_1
     323: iload         7
     325: aaload
     326: iload         4
     328: aload         5
     330: iload         6
     332: iinc          6, 1
     335: invokeinterface #63,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     340: checkcast     #65                 // class java/lang/Number
     343: invokevirtual #69                 // Method java/lang/Number.intValue:()I
     346: iastore
     347: iinc          7, 1
     350: goto          315
     353: iload_2
     354: iload_3
     355: iadd
     356: iconst_2
     357: isub
     358: istore        7
     360: iload_2
     361: iload         7
     363: if_icmpgt     403
     366: aload_1
     367: iload         4
     369: aaload
     370: iload         7
     372: aload         5
     374: iload         6
     376: iinc          6, 1
     379: invokeinterface #63,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     384: checkcast     #65                 // class java/lang/Number
     387: invokevirtual #69                 // Method java/lang/Number.intValue:()I
     390: iastore
     391: iload         7
     393: iload_2
     394: if_icmpeq     403
     397: iinc          7, -1
     400: goto          366
     403: iload_2
     404: iload_3
     405: iadd
     406: iconst_2
     407: isub
     408: istore        7
     410: iload_2
     411: iconst_1
     412: iadd
     413: istore        8
     415: iload         8
     417: iload         7
     419: if_icmpgt     459
     422: aload_1
     423: iload         7
     425: aaload
     426: iload_2
     427: aload         5
     429: iload         6
     431: iinc          6, 1
     434: invokeinterface #63,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     439: checkcast     #65                 // class java/lang/Number
     442: invokevirtual #69                 // Method java/lang/Number.intValue:()I
     445: iastore
     446: iload         7
     448: iload         8
     450: if_icmpeq     459
     453: iinc          7, -1
     456: goto          422
     459: return
}


package com.leetcode

// https://leetcode.com/problems/repeated-dna-sequences/
class P187 {
    fun findRepeatedDnaSequences(s: String): List<String> {
        val answer = mutableSetOf<String>()
        if (s.length <= 10) return listOf()
        // 해시값들이 들어갈 Set
        val seen = mutableSetOf<Int>()
        // 처음 10자리를 해싱한다.
        var hash = 0
        for (i in 0 until 10) {
            hash = hash.shl(2) + int(s[i])
        }
        // 처음 만들어진 해시를 저장
        seen += hash
        // 나머지 해시값 비교
        for (i in 10 until s.length) {
            // 해시값을 조정한다.
            hash = hash.and(1.shl(18) - 1)
            hash = hash.shl(2) + int(s[i])
            // Set에 add() 했을 때 false면 이미 값이 있다는 것이다.
            if (!seen.add(hash)) {
                answer.add(s.substring(i - 9, i + 1))
            }
        }
        return answer.toList()
    }

    private fun int(ch: Char): Int {
        return when (ch) {
            'A' -> 0
            'C' -> 1
            'G' -> 2
            'T' -> 3
            else -> 0
        }
    }
}

Compiled from "P187.kt"
public final class com.leetcode.P187 {
  public com.leetcode.P187();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final java.util.List<java.lang.String> findRepeatedDnaSequences(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #16                 // String s
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #24                 // class java/util/LinkedHashSet
       9: dup
      10: invokespecial #25                 // Method java/util/LinkedHashSet."<init>":()V
      13: checkcast     #27                 // class java/util/Set
      16: astore_2
      17: aload_1
      18: invokevirtual #33                 // Method java/lang/String.length:()I
      21: bipush        10
      23: if_icmpgt     30
      26: invokestatic  #39                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      29: areturn
      30: new           #24                 // class java/util/LinkedHashSet
      33: dup
      34: invokespecial #25                 // Method java/util/LinkedHashSet."<init>":()V
      37: checkcast     #27                 // class java/util/Set
      40: astore_3
      41: iconst_0
      42: istore        4
      44: iconst_0
      45: istore        5
      47: iload         5
      49: bipush        10
      51: if_icmpge     77
      54: iload         4
      56: iconst_2
      57: ishl
      58: aload_0
      59: aload_1
      60: iload         5
      62: invokevirtual #43                 // Method java/lang/String.charAt:(I)C
      65: invokespecial #47                 // Method int:(C)I
      68: iadd
      69: istore        4
      71: iinc          5, 1
      74: goto          47
      77: iload         4
      79: invokestatic  #53                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      82: astore        6
      84: aload_3
      85: checkcast     #55                 // class java/util/Collection
      88: aload         6
      90: invokeinterface #59,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      95: pop
      96: bipush        10
      98: istore        5
     100: aload_1
     101: invokevirtual #33                 // Method java/lang/String.length:()I
     104: istore        6
     106: iload         5
     108: iload         6
     110: if_icmpge     183
     113: iload         4
     115: ldc           #60                 // int 262143
     117: iand
     118: istore        4
     120: iload         4
     122: iconst_2
     123: ishl
     124: aload_0
     125: aload_1
     126: iload         5
     128: invokevirtual #43                 // Method java/lang/String.charAt:(I)C
     131: invokespecial #47                 // Method int:(C)I
     134: iadd
     135: istore        4
     137: aload_3
     138: iload         4
     140: invokestatic  #53                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     143: invokeinterface #61,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     148: ifne          177
     151: aload_2
     152: aload_1
     153: iload         5
     155: bipush        9
     157: isub
     158: iload         5
     160: iconst_1
     161: iadd
     162: invokevirtual #65                 // Method java/lang/String.substring:(II)Ljava/lang/String;
     165: dup
     166: ldc           #67                 // String substring(...)
     168: invokestatic  #70                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     171: invokeinterface #61,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     176: pop
     177: iinc          5, 1
     180: goto          106
     183: aload_2
     184: checkcast     #72                 // class java/lang/Iterable
     187: invokestatic  #76                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     190: areturn

  private final int int(char);
    Code:
       0: iload_1
       1: lookupswitch  { // 4
                    65: 44
                    67: 48
                    71: 52
                    84: 56
               default: 60
          }
      44: iconst_0
      45: goto          61
      48: iconst_1
      49: goto          61
      52: iconst_2
      53: goto          61
      56: iconst_3
      57: goto          61
      60: iconst_0
      61: ireturn
}


package com.leetcode

// https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
class P167 {
    fun twoSum(numbers: IntArray, target: Int): IntArray {
        // target 보다 작은 수의 조합만 찾으면 된다.
        var endOfSearch = numbers.lastIndex - 1
        for (i in numbers.indices) {
            if (numbers[i] > target) {
                endOfSearch = i - 1
                break
            }
        }
        // Binary Search
        for (i in 0..endOfSearch) {
            val j = binarySearch(numbers, i + 1, numbers.lastIndex, target - numbers[i])
            if (j > -1) return intArrayOf(i + 1, j + 1)
        }
        // You may assume that each input would have exactly one solution and you may not use the same element twice.
        return IntArray(0)
    }

    private fun binarySearch(numbers: IntArray, s: Int, e: Int, target: Int): Int {
        if (s > e) return -1
        val m = (s + e) / 2
        return with(numbers[m]) {
            when {
                target < this -> binarySearch(numbers, s, m - 1, target)
                target > this -> binarySearch(numbers, m + 1, e, target)
                else -> m
            }
        }
    }
}

Compiled from "P167.kt"
public final class com.leetcode.P167 {
  public com.leetcode.P167();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int[] twoSum(int[], int);
    Code:
       0: aload_1
       1: ldc           #15                 // String numbers
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #27                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      10: iconst_1
      11: isub
      12: istore_3
      13: iconst_0
      14: istore        4
      16: aload_1
      17: arraylength
      18: istore        5
      20: iload         4
      22: iload         5
      24: if_icmpge     49
      27: aload_1
      28: iload         4
      30: iaload
      31: iload_2
      32: if_icmple     43
      35: iload         4
      37: iconst_1
      38: isub
      39: istore_3
      40: goto          49
      43: iinc          4, 1
      46: goto          20
      49: iconst_0
      50: istore        4
      52: iload_3
      53: istore        5
      55: iload         4
      57: iload         5
      59: if_icmpgt     126
      62: aload_0
      63: aload_1
      64: iload         4
      66: iconst_1
      67: iadd
      68: aload_1
      69: invokestatic  #27                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      72: iload_2
      73: aload_1
      74: iload         4
      76: iaload
      77: isub
      78: invokespecial #31                 // Method binarySearch:([IIII)I
      81: istore        6
      83: iload         6
      85: iconst_m1
      86: if_icmple     113
      89: iconst_2
      90: newarray       int
      92: astore        7
      94: aload         7
      96: iconst_0
      97: iload         4
      99: iconst_1
     100: iadd
     101: iastore
     102: aload         7
     104: iconst_1
     105: iload         6
     107: iconst_1
     108: iadd
     109: iastore
     110: aload         7
     112: areturn
     113: iload         4
     115: iload         5
     117: if_icmpeq     126
     120: iinc          4, 1
     123: goto          62
     126: iconst_0
     127: newarray       int
     129: areturn

  private final int binarySearch(int[], int, int, int);
    Code:
       0: iload_2
       1: iload_3
       2: if_icmple     7
       5: iconst_m1
       6: ireturn
       7: iload_2
       8: iload_3
       9: iadd
      10: iconst_2
      11: idiv
      12: istore        5
      14: aload_1
      15: iload         5
      17: iaload
      18: istore        6
      20: iconst_0
      21: istore        7
      23: nop
      24: iload         4
      26: iload         6
      28: if_icmpge     46
      31: aload_0
      32: aload_1
      33: iload_2
      34: iload         5
      36: iconst_1
      37: isub
      38: iload         4
      40: invokespecial #31                 // Method binarySearch:([IIII)I
      43: goto          70
      46: iload         4
      48: iload         6
      50: if_icmple     68
      53: aload_0
      54: aload_1
      55: iload         5
      57: iconst_1
      58: iadd
      59: iload_3
      60: iload         4
      62: invokespecial #31                 // Method binarySearch:([IIII)I
      65: goto          70
      68: iload         5
      70: nop
      71: nop
      72: ireturn
}


package org.baichuan.sample.algorithms.leetcode.middle

/**
 * @author: tk (<EMAIL>)
 * @date: 2022/1/10
 *
 * leetcode 11 盛最多水的容器
 * https://leetcode-cn.com/problems/container-with-most-water/
 */
class MaxArea {
    /**
     * 解题思路(双指针法思路浅析)：
     * 题目要求找出盛水最多的容器，那么哪些因素会影响到盛水量呢？首先，盛水量完全取决于底*min(左高, 右高)，
     * 所以，我们可以从底最大的时候开始遍历数组进行计算，这样的好处是当我们从"两边往中间靠的过程"中就不用考虑存在更大的底而对计算结果造成影响了。
     * 接下来是应该怎么往中间靠？答案是哪边"更低"哪边往中间靠，为什么呢？因为从高度上来说，决定盛水量的是最低的那一边。只有这一边变大才有可能使得容器的盛水量增加。
     * 最后就是循环这个往中间靠的过程了。
     */
    fun maxArea(height: IntArray): Int {
        var result = 0
        var left = 0
        var right = height.size - 1
        var i = 1
        while (left < right) {
            val tmp = if (height[left] > height[right]) {
                right--
                height[right] * ((height.size - i))
            } else {
                left++
                height[left] * ((height.size - i))
            }
            result = tmp.coerceAtLeast(result)
            i++
        }

        return result
    }
}

Compiled from "MaxArea.kt"
public final class org.baichuan.sample.algorithms.leetcode.middle.MaxArea {
  public org.baichuan.sample.algorithms.leetcode.middle.MaxArea();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int maxArea(int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String height
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: aload_1
      11: arraylength
      12: iconst_1
      13: isub
      14: istore        4
      16: iconst_1
      17: istore        5
      19: iload_3
      20: iload         4
      22: if_icmpge     78
      25: aload_1
      26: iload_3
      27: iaload
      28: aload_1
      29: iload         4
      31: iaload
      32: if_icmple     51
      35: iinc          4, -1
      38: aload_1
      39: iload         4
      41: iaload
      42: aload_1
      43: arraylength
      44: iload         5
      46: isub
      47: imul
      48: goto          63
      51: iinc          3, 1
      54: aload_1
      55: iload_3
      56: iaload
      57: aload_1
      58: arraylength
      59: iload         5
      61: isub
      62: imul
      63: istore        6
      65: iload         6
      67: iload_2
      68: invokestatic  #27                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
      71: istore_2
      72: iinc          5, 1
      75: goto          19
      78: iload_2
      79: ireturn
}