늘 박살나는건 나였음에... leetcode 80문제를 풀고 프로그래머스를
도전하였다.. 근데 생각보다 ..쉽지 않아서 눈물이 났다.. 프로그래머스도
뿌셔보기로 하겠다.


index 을 배출해내는것으로 location 2 에 있는 3 이 언제 나오게 될까를 구하는 식이다.
테스트 케이스 2 를 보지 못하고
1.매번 큰수가 나오게 되는데 > 그럼 큰수가 나오지 않을 경우라면 그냥 shift 를해서 count 값을 내놓자 싶었다.
2. 하지만 index 를 생각못하고 1이 나오는 경우! 에만 코드를 짜게 되니 테스트 케이스 에서 1이 나오는 경우가 1이 되고말았다.
3. 그럼 [key. value] 형식으로 max 값을 구해서 >max 값이 있는경우의 index값을 배출시키자싶었다.
근데 math.max 가 2중문으로 어떻게 구하지 ? 여기서 부터 막혔다.
1)spice 함수를 사용해서 최대값 찾고 > 재조합 > shift 하지말고
2)우선뽑고 경우의 수를 본뒤에 넣을까 말까 고민하기
!priorities.map((priority, index) => [priority, index])
map 으로 코드가 간편해졌다. 나는 새로운 배열을 만들어서 index를 넣어줬었다.
priorities.findIndex(([value, _]) => value > gapp)
findindex 문이 이중 문을 사용할수 있다는 것을 알게 되었다.
function solution(priorities, location)
{
var count=1;
priorities = priorities.map((priority, index) => [priority, index])
while(true){
var [gapp,index]= priorities.shift();
const find__max_index = priorities.findIndex(([value, _]) => value > gapp)
//이값보다 큰 값의 인덱스 찾으면
if(find__max_index!=-1){
priorities.push([gapp,index]);
continue;
}
else{
count+=1;
// 이값보다 큰값 못찾은경우
if(index==location){
count-=1;
return count;
}
}
}
return count;
}