function insertSortLog(arr){ var n = arr.length-1 var unsorted = true var tmp = arr[n] var log = [] while(unsorted){ if(tmp < arr[n-1]) { arr[n] = arr[n-1] n-- } else { arr[n] = tmp unsorted = false } console.log(arr.join(' ')) } } function processData(input) { //Enter your code here input = input.split('\n') var n = input[0] var arr = input[1].split(' ') insertSortLog(arr) } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });
2017년 9월 19일 화요일
Javascript Solution - Insertion Sort - Part 1
hackkerank Insertion Sort - Part 1
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기