leetcode
-
[leetcode] 27. Remove Element알고리즘 2021. 11. 9. 22:53
Description 정수로 이루어진 nums 배열과 특정 값 val 이 매개변수로 주어졌을때 배열 안에 val 과 동일한 값이 있으면 해당 배열에서 제거한 후 배열안에 유효한 값이 몇개인지를 출력하는 문제 Input: nums = [3,2,2,3], val = 3 Output: 2, nums = [2,2,_,_] Input: nums = [0,1,2,2,3,0,4,2], val = 2 Output: 5, nums = [0,1,4,0,3,_,_,_] Success cnt와 i 라는 두 개의 변수를 두어 nums[i] 의 값이 val 과 같지 않으면 cnt 가 가르키는 인덱스로 값을 채워 나간다. 그렇게 값을 채워나가다 보면 cnt 에는 val 의 값에 해당되지 않는 유효한 값들만 존재하게되고 cnt 는 ..
-
[leetcode] 88. Merge Sorted Array알고리즘 2021. 11. 8. 21:52
Description nums1 배열과 해당 배열에 유효한 값이 몇개인지를 나타내는 수 m nums2 배열과 해당 배열에 유효한 값이 몇개인지를 나타내는 수 n 위 값들이 매개변수로 들어왔을때 새로운 배열 생성없이 두 배열을 하나의 배열로 합친 후 내림차순으로 정렬하라. Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Input: nums1 = [1], m = 1, nums2 = [], n = 0 Output: [1] Input: nums1 = [0], m = 0, nums2 = [1], n = 1 Output: [1] Success m 부터 m+n 까지 반복문을 돌려 nums1 배열의 끝 지점에 nums2..
-
[leetcode] 977. Squares of a Sorted Array알고리즘 2021. 11. 6. 15:51
Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com [Success] 내림차순으로 정렬된 정수 배열이 주어졌을 때, 내림차순으로 정렬된 각 인덱스 값의 제곱 구하는 문제 [풀이] 각 인덱스의 값의 제곱을 구한 후 해당 인덱스에 다시 할당시킨다. 제곱의 값으로 다 채워진 후에는 해당 배열을 내림차순으로 정렬. class Solution { public int..
-
[leetcode] Find Numbers with Even Number of Digits알고리즘 2021. 11. 6. 14:24
Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com [Success] 정수 배열이 주어졌을 때, 자릿수가 짝수인 값은 몇개인지 반환하는 문제 [풀이] Math.log10 라는 함수를 이용하여 정수 값의 자릿수를 알아 낸 후 자릿수가 짝수인지 확인하여 짝수라면 카운트 값을 증가시킨 후 반환한다. class Solution { public static int ..
-
[leetcode] 485. Max Consecutive Ones알고리즘 2021. 11. 6. 10:31
Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com [Success] 이진수로 구성된 배열이 주어졌을 때, 연속되는 1의 값의 최대 수를 구하는 문제 풀이 배열길이 만큼 돌면서 특정 인덱스 값이 1 이면, count 값을 증가시키고 count 가 최대 값으로 설정될 때마다 maxCount 에 할당해준 후 최종적으로 maxCount 를 return 시킨다. ..
-
[leetcode] Squares of a Sorted Array알고리즘 2021. 9. 3. 22:49
https://leetcode.com/explore/learn/card/fun-with-arrays/523/conclusion/3574/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com Success 오름차순으로 정렬된 배열이 주어졌을 때 , 각 원소의 값을 제곱한 후 오름차순 되어 있는 상태로 반환 해야한다. 풀이 각 원소에 값을 제곱을 하여 새로 값..
-
[leetcode] Find All Numbers Disappeared in an Array알고리즘 2021. 9. 3. 22:00
https://leetcode.com/explore/learn/card/fun-with-arrays/523/conclusion/3270/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com Success 위 문제는 n 만큼의 길이를 가진 배열이 주어졌을 때, 해당 원소의 값이 1부터 ~ n까지로 채워져야 하는데 1~n 사이에 값 중 없는 값을 찾아서 Lis..
-
[leetcode] Third Maximum Number알고리즘 2021. 9. 3. 18:17
https://leetcode.com/explore/learn/card/fun-with-arrays/523/conclusion/3231/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com Success 해당 문제는 배열이 주어졌을 때 세번째로 큰 값을 리턴하는 문제이다. 이때 배열의 길이가 3보다 작을경우엔 가장 큰 값을 리턴하며, 중복된 원소는 하나의 ..