Skip to content

Conversation

@syoshida20
Copy link
Owner

@syoshida20 syoshida20 commented Apr 17, 2025

問題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

@syoshida20 syoshida20 self-assigned this Apr 17, 2025
@syoshida20 syoshida20 force-pushed the feature/stack/reverse-linked-list branch from 0680a38 to 6366cea Compare April 17, 2025 00:16
@syoshida20 syoshida20 marked this pull request as ready for review April 20, 2025 12:56
Copy link

@huyfififi huyfififi left a 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) {
Copy link

@huyfififi huyfififi Apr 20, 2025

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を作る方が無難かなと感じます。
が、私の感覚が間違っている可能性があるので、他の方々のご意見を伺いたいところです 👀

Copy link

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

Copy link
Owner Author

@syoshida20 syoshida20 May 6, 2025

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...
}

参考: https://stackoverflow.com/questions/11796093/is-there-a-way-to-provide-named-parameters-in-a-function-call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants