Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- vuex
- mixins
- v-for
- Login
- 콘솔한글깨짐
- Express.js
- node.js
- Reduce
- v-on
- getters
- includes
- javascipt
- v-if
- javscript
- 연동
- Vue.js
- IntelliJ
- kibana
- JavaScript
- programmers
- sns로그인
- 템플릿문법
- state
- mutations
- Emit
- 음양더하기
- react
- azure
- KAKAO
- axios
Archives
- Today
- Total
공부용
주식가격 본문
문제 설명
초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요.
제한사항
- prices의 각 가격은 1 이상 10,000 이하인 자연수입니다.
- prices의 길이는 2 이상 100,000 이하입니다.
class Solution {
public int[] solution(int[] prices) {
int answer[] = new int[prices.length];
for(int i=0; i<prices.length; i++) {
int price = prices[i];
int time = (prices.length-1)-i;
for(int j=i+1; j<prices.length; j++) {
if(price > prices[j]) {
time = j-i;
break;
}
}
answer[i] = time;
}
return answer;
}
}
처음에 2중 for문 안에 time을 정의할때 많이 헤맸다.
배열은 0부터 시작이고 초단위 1초단위라.. 그게 좀 아리송아리송
Comments