본문 바로가기

전체 글236

[Android] Strong, Soft, Weak, Phantom Reference 메모리 관리안드로이드 디바이스는 제한된 메모리 자원을 가지고 있기 때문에 *메모리 누수가 발생하면 앱의 성능이 저하되고, 심각한 경우 앱이 강제 종료될 수 있기 때문에 메모리 관리는 중요하다.메모리 누수(Memory Leak) : 프로그램이 동적으로 할당한 메모리 영역 중 일부를 더 이상 사용하지 않음에도 불구하고 해제하지 않아, 사용할 수 있는 메모리가 점점 줄어드는 현상앱이 종료될 때 참조하고 있는 객체가 남아있어 메모리 누수가 발생할 수 있기 때문에, 애플리케이션 컨텍스트를 멤버 변수로 사용하지 않는 것이 좋다.Weak Reference 는 객체가 더 이상 사용되지 않을 때 GC 가 해당 객체를 수거할 수 있기 때문에, Weak Reference 를 적절히 활용하는 것이 중요하다.GC(Carbase.. 2024. 10. 21.
[LeetCode][Kotlin] 42. Trapping Rain Water 42. Trapping Rain WaterGiven n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.너비가 1인 고도 지도를 나타내는 음이 아닌 정수 n개가 주어졌을 때, 비가 내린 후에 얼마나 많은 물을 가둘 수 있는지 계산하세요. Example 1:Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]Output: 6Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1.. 2024. 10. 21.
[LeetCode][Kotlin] 1578. Minimum Time to Make Rope Colorful 1578. Minimum Time to Make Rope ColorfulAlice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the ith balloon. Alice wants the rope to be colorful. She does not want two consecutive balloons to be of the same color, so she asks Bob for help. Bob can remove some balloons from the rope to make it colorful. You are given a 0-indexed integer.. 2024. 10. 19.
[LeetCode][Kotlin] 779. K-th Symbol in Grammar 779. K-th Symbol in GrammarWe build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.For example, for n = 3, the 1st row is 0, the 2nd row is 01, and the 3rd row is 0110.Given two integer n and k, return the kth (1-indexed) symbol in the nth row .. 2024. 10. 19.
[LeetCode][Kotlin] 189. Rotate Array 189. Rotate ArrayGiven an integer array nums, rotate the array to the right by k steps, where k is non-negative.정수 배열 nums가 주어지면, 배열을 k 단계만큼 오른쪽으로 회전합니다. 여기서 k는 음수가 아닙니다. Example 1:Input: nums = [1,2,3,4,5,6,7], k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1,2,3,4,5,6]rotate 2 steps to the right: [6,7,1,2,3,4,5]rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2:Inp.. 2024. 10. 19.
[LeetCode][Kotlin] 1498. Number of Subsequences That Satisfy the Given Sum Condition 1498. Number of Subsequences That Satisfy the Given Sum ConditionYou are given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 109 + 7.정수 nums와 정수 target의 배열이 주어집니다. nums의 비어 있지 않은 부분 시퀀스의 개수를 반환합니다. 이 부분 시.. 2024. 10. 19.
[LeetCode][Kotlin] 18. 4Sum 18. 4SumGiven an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:0 a, b, c, and d are distinct.nums[a] + nums[b] + nums[c] + nums[d] == targetYou may return the answer in any order.n개의 정수로 구성된 배열 nums가 주어지면 다음과 같은 모든 고유한 사중항 [nums[a], nums[b], nums[c], nums[d]]의 배열을 반환합니다.- 0 - a, b, c, d는 서로 다릅니다. - nums[a] + nums[b] + nums[.. 2024. 10. 19.