-
Notifications
You must be signed in to change notification settings - Fork 0
206. Reverse Linked List #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
0680a38 to
6366cea
Compare
huyfififi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多くのパターンが検討されていて勉強になりました!コードも特に引っかかるところがなく、良いと思います 👍
| * 一番後ろの人を次の人から受け取り、返す。 | ||
|
|
||
| ```javascript | ||
| const reverseList = function(current, previous = null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LeetCode側でのfunction callにprevious = nullという値を追加しているようですが、function signatureを変えてしまうのは問題設定を変えてしまっているような気がしてやや抵抗感があります。どこまで許されるかは面接官・業務ならコード・チーム次第だと思いますが、別解でやられているように別途helper functionを作る方が無難かなと感じます。
が、私の感覚が間違っている可能性があるので、他の方々のご意見を伺いたいところです 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaScript の呼び出しは順番によるもののみで、Python Ruby にあるようなキーワード引数がありません。
このため、名前を書き換えても問題はないはずです。
Python は問題があるかもしれませんね。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.wqduubixdpe4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javascriptのドキュメントを読んだところ、キーワード引数に関する記載はなく、順序の記載のみでした。
The argument order within the function call should be the same as the parameters order in the function definition.
参考 : https://developer.mozilla.org/en-US/docs/Glossary/Argument
また、Destructuring objects as function parametersという方法で、
キーワード引数に似たことはできるそうです。
myFunction({ param1 : 70, param2 : 175});
function myFunction({param1, param2}={}){
// ...function body...
}
問題URL
https://leetcode.com/problems/reverse-linked-list/
問題文
Given the head of a singly linked list, reverse the list, and return the reversed list.
Example 1:
Input: head = [1,2,3,4,5]
Output: [5,4,3,2,1]
Example 2:
Input: head = [1,2]
Output: [2,1]
Example 3:
Input: head = []
Output: []
Constraints:
The number of nodes in the list is the range [0, 5000].
-5000 <= Node.val <= 5000