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
Javascript Solution - Intro to Tutorial Challenges
hackkerank Intro to Tutorial Challenges
function processData(input) { //Enter your code here input = input.split('\n') var V = input[0] var n = input[1] var ar = input[2].split(' ') console.log(ar.indexOf(V)) } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });
Javascript Solution - Big Sorting Solution
hackkerank Big Sorting Solution
process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function compare(a,b){ if(a.length > b.length){ return 1 } else if(a.length < b.length){ return -1 } var unsolve = true,idx = 0 var char_a,char_b while(unsolve){ char_a = parseInt(a.charAt(idx)) char_b = parseInt(b.charAt(idx)) if(isNaN(char_a)){ return 0 } if(char_a > char_b){ return 1 } else if(char_a < char_b){ return -1 } else{ idx++ } } } function main() { var n = parseInt(readLine()); var unsorted = []; for(var unsorted_i = 0; unsorted_i < n; unsorted_i++){ unsorted[unsorted_i] = readLine(); } // your code goes here var sorted = unsorted.sort(compare) console.log(sorted.join('\n')) }
피드 구독하기:
글 (Atom)