We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 65ef457 + 1a6de5a commit 1ea5128Copy full SHA for 1ea5128
src/main/scala/org/codecraftlabs/leetcode/ReverseLinkedList.scala
@@ -4,9 +4,14 @@ import scala.collection.mutable
4
5
object ReverseLinkedList {
6
def reverseList(head: ListNode): ListNode = {
7
- val nodeStack = mutable.ArrayStack[ListNode]()
8
- process(head, nodeStack)
9
- nodeStack.head
+ if (head == null) {
+ head
+ } else {
10
+ val nodeStack = mutable.ArrayStack[ListNode]()
11
+ process(head, nodeStack)
12
+ nodeStack.head
13
+ }
14
+
15
}
16
17
private def process(node: ListNode, nodeStack: mutable.ArrayStack[ListNode]): Unit = {
0 commit comments