Algorithm/LeetCode7 [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] Merge Sorted Array (Kotlin) https://leetcode.com/problems/merge-sorted-array Merge Sorted Array - LeetCode Merge Sorted Array - You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-de leetcode.com fun merge(nums1: IntArray, m: Int, nums2: IntArra.. 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 다음