배열만들기4
-
[프로그래머스] 배열 만들기 4알고리즘 노트 2023. 10. 16. 12:41
조건이 조금 복잡하긴 하지만, 결국 i를 어디서 증가시켜주느냐를 잘 판단하면 문제 없이 해결 가능할 것 같습니다. 코드가 조금 지저분하긴 하네요.. [문제 풀이] 1. 가변 데이터를 담기 위한 List 선언 2. 주어지는 arr만큼 for문을 돌 수 있도록 선언하며 i 증감 문법은 제외 3. list가 비어있거나, list의 마지막 요소가 arr[i]보다 작으면 list에 arr[i]를 추가하고 i 증가 4. arr[i]가 list의 마지막 요소보다 크거나 같으면 마지막 요소를 제거 이전에 사용했던 Stream의 skip함수를 사용해서 마지막 요소에 손쉽게 접근할 수 있었습니다.