๋ฌธ์
ํ์ด ๊ณผ์
์ฐ๊ฒฐ ๋ฆฌ์คํธ
์ ํฌ์ธํฐ๋ฅผ ๋ค์ง๋ ์ฐ์ฐ์ ๊ตฌํํ๋ ๋ฌธ์ ์
๋๋ค.
๊ฐ์ฅ ์ง๊ด์ ์ธ ๋ฐฉ๋ฒ์ผ๋ก ์ฌ๊ท ํธ์ถ
์ ์ด์ฉํด์ ๊ตฌํํ์์ต๋๋ค.
๊ฐ๊ฐ์ ์ฌ๊ท ํธ์ถ์ ๋ค์ ๋
ธ๋๋ถํฐ ๋ ๋
ธ๋๊น์ง์ ๋ค์งํ ๊ฒฐ๊ณผ๋ฅผ ๊ธฐ๋ํ๋ฉฐ
ํด๋น ๊ฒฐ๊ณผ๋ฅผ ํ ๋๋ก ํ์ฌ ๋
ธ๋์ ํฌ์ธํฐ ๊ฐ์ ๋ณ๊ฒฝํฉ๋๋ค.
์ฝ๋
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var reverseList = function (head) {
let newHead = null;
function reverse(cur) {
if (!cur) return null;
const next = reverse(cur.next);
if (next) next.next = cur;
else newHead = cur;
return cur;
}
reverse(head);
if (head) head.next = null;
return newHead;
};
๋ฐ์ํ
'๐ algorithm > leetcode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
LeetCode 771 - Jewels and Stones (Easy) (0) | 2021.03.03 |
---|---|
LeetCode 5 - Longest Palindromic Substring (Medium) (0) | 2021.03.03 |
LeetCode 136 - Single Number (Easy) (0) | 2021.03.03 |
LeetCode 104 - Maximum Depth of Binary Tree (Easy) (0) | 2021.03.03 |
LeetCode 102 - Binary Tree Level Order Traversal (Medium) (0) | 2021.03.03 |
๐ฌ ๋๊ธ