본문 바로가기

leetcode48

leetCode] Contains Duplicate / Kotlin https://leetcode.com/explore/featured/card/top-interview-questions-easy/92/array/578/   Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.  class Solution { fun containsDuplicate(nums: IntArray): Boolean { // nums에서 중복제거 된 배열을 정의하고 var distinctArr = nums.distinct() // 배열.. 2024. 12. 17.
leetcode] Single Number / Kotlin int 배열에서 한 값 빼고  중복으로 들어있는데중복이 아닌 값 리턴하는 문제. 전체 돌면서 같은거 없으면 그 값 리턴한다.class Solution { fun singleNumber(nums: IntArray): Int { var ans = 0 for(i in 0 until nums.size) { var isSingle = true for(j in 0 until nums.size) { if(i == j) continue if(nums[i] == nums[j]) isSi.. 2024. 10. 16.
leetcode] Rotate Array / Kotlin https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/646/   class Solution { fun rotate(nums: IntArray, k: Int): Unit { // 이동할 위치 계산 val rotation = k % nums.size // 새로운 배열에 이동된 값 저장 val arr = IntArray(nums.size) for(i in nums.indices) { arr[(i+rotation) % nums.size] = nums[i] } //.. 2024. 10. 16.
78] 1672. Richest Customer Wealth Kotlin https://leetcode.com/problems/richest-customer-wealth/description/ Richest Customer Wealth - LeetCode Can you solve this real interview question? Richest Customer Wealth - You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i th customer has in the j th bank. Return the wealth that the richest customer has. A custom leetcode.com 2차원 int 배열이 주어질때 각 행의 합 중 .. 2023. 4. 19.