Skip to content

Commit ebfb4dd

Browse files
committed
Ruby solution for 024
1 parent 91eb35f commit ebfb4dd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Definition for singly-linked list.
2+
# class ListNode
3+
# attr_accessor :val, :next
4+
# def initialize(val)
5+
# @val = val
6+
# @next = nil
7+
# end
8+
# end
9+
10+
# @param {ListNode} head
11+
# @return {ListNode}
12+
def swap_pairs(head)
13+
if head.nil? || head.next.nil?
14+
return head
15+
end
16+
17+
res = head.next
18+
tmp = head.next.next
19+
head.next.next = head
20+
head.next = swap_pairs(tmp)
21+
22+
res
23+
end

solution/031.Next Permutation/Solution.rb

Whitespace-only changes.

0 commit comments

Comments
 (0)