Leetcode6 [LeetCode] Symmetric Tree (Kotlin) https://leetcode.com/problems/symmetric-tree fun isSymmetric(root: TreeNode?): Boolean { if (root == null) { return true } return isEqual(root.left, root.right) } fun isEqual(left: TreeNode?, right: TreeNode?): Boolean { if (left == null && right == null) { return true } if (left == null || right == null) { return false } if (left.`val` != right.`val`) { return false } return isEqual(left.left, .. 2023. 1. 14. [LeetCode] Two Sum (Kotlin) class Solution { fun twoSum(nums: IntArray, target: Int): IntArray { val map = mutableMapOf() for ((i, v) in nums.withIndex()) { if (map.containsKey(target - v)) { return intArrayOf(map[target - v]!!, i) } map[v] = i } return intArrayOf() } } 2022. 12. 2. 이전 1 2 다음