ย
ย
ํ์ด๋ณด๊ธฐ
function Train(number) {
this.number = number;
this.next = null;
}
function LinkedList() {
this.head = null;
}
function answer(nums) {
let ll = new LinkedList();
for (let x of nums) {
let current = new Train(x);
// ๋งจ ์ฒ์ ๋
ธ๋๋ head์ ๋ฃ์ด์ฃผ์ด์ผ ๋๋ค.
if (ll.head == null) ll.head = current;
// ์ด๋ฏธ ๋
ธ๋๊ฐ ์กด์ฌํ๋ค๋ฉด prev๋ ๋ญ๊ฐ ์์ ๊ฒ์ด๋ค. ์ด ๋ค์์๋ค ๋งค๋ฌ๊ณ prev๋ฅผ ์
๋ฐ์ดํธํ๋ค.
else prev.next = current;
prev = current;
}
return ll;
}