Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2dc80ea

Browse filesBrowse files
authored
Merge pull request #100 from supaggregator/master
add scala solution for 208 Implement-Trie.scala
2 parents c09fe79 + 38df940 commit 2dc80ea
Copy full SHA for 2dc80ea

File tree

Expand file treeCollapse file tree

1 file changed

+26
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-0
lines changed
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Since the question asks for a O(1) space complexity and O(nodes) time complexity
2+
// I decide to make no difference to a java solution...
3+
object Solution {
4+
def oddEvenList(head: ListNode): ListNode = {
5+
if (head == null)
6+
null
7+
else{
8+
// Initialize two LinkedList
9+
var currentOdd = head
10+
var currentEven = head.next
11+
var firstEven = currentEven
12+
13+
while (currentEven != null && currentEven.next != null) {
14+
currentOdd.next = currentEven.next
15+
currentOdd = currentOdd.next
16+
currentEven.next = currentOdd.next
17+
currentEven = currentEven.next
18+
}
19+
// Combine two LinkedList
20+
currentOdd.next = firstEven
21+
22+
head
23+
}
24+
25+
}
26+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.