본문 바로가기

분류 전체보기311

Android] Fragment 생성시에는 newInstance로. All subclasses of Fragment must include a public no-argument constructor. The framework will often re-instantiate a fragment class when needed, in particular during state restore, and needs to be able to find this constructor to instantiate it. If the no-argument constructor is not available, a runtime exception will occur in some cases during state restore. 화면회전이나 화면 재생성으로 인해 Fragment 재생성시 no-a.. 2025. 1. 24.
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.