알고리즘 7

[LeetCode] Squares of a Sorted Array

https://leetcode.com/explore/learn/card/fun-with-arrays/521/introduction/3240/ 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 문제 정수 배열에 있는값들을 제곱근하고 정렬 후 출력하세요 풀이 class Solution { public int[] sortedSquares(int[] nums) ..

알고리즘 2021.09.15

[Leetcode] Find Numbers with Even Number of Digits

https://leetcode.com/explore/learn/card/fun-with-arrays/521/introduction/3237/ 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 문제 정수로 되어있는 배열이 주어진다. 배열 길이에 짝수가 몇개인지 알아보는 문제이다 풀이 class Solution { public int findNumbers(i..

알고리즘 2021.09.12

[Leetcode]Max Consecutive Ones

https://leetcode.com/explore/learn/card/fun-with-arrays/521/introduction/3238/ 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을 반환한다. 풀이 nums[i] 에는 0과 1로 이루어져있다. [1,0,0,1,1,0,1] 이 있다..

알고리즘 2021.09.09

[LeetCode]Find All Numbers Disappeared in an Array

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 배열을 정렬하고 [1,n] 사이에 없는 숫자를 찾아 넣어야한다. 풀이 먼저 nums의 배열을 정렬한 후 nums의 길이을 i만큼 돌리는데 binarySea..

알고리즘 2021.09.06

[leetcode]Replace Elements with Greatest Element on Right Side

배열이 주어지면 해당 배열의 arr모든 요소를 오른쪽에 있는 요소 중 가장 큰 요소로 바꾸고 마지막 요소를 -1로 바꾸는 문제이다. 이 문제의 핵심은 배열 어디서 부터 찾을것이고 어떻게 큰 값을 찾는지가 중요한것같다 public class Solution { public int[] replaceElements(int[] arr) { int max = -1; for(int i=arr.length-1; i>=0; i--){ int v = arr[i]; arr[i]=max; max = Math.max(v,max); } return arr; } } 먼저 arr를 뒤에서 부터 돌게 해주었다. arr의 인덱스 i를 변수 v에 담아주고 max값을 arr의 index i자리에 넣어 주었다. 그 이후 max값을 담아준 ..

알고리즘 2021.07.27