-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path21. Merge Two Sorted Lists.rb
More file actions
50 lines (48 loc) · 933 Bytes
/
21. Merge Two Sorted Lists.rb
File metadata and controls
50 lines (48 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def merge_two_lists(l1, l2)
=begin
if !l2
return l1
else
if l1.val==l2.val
temp=l1.next
temp1=l2.next
l1=l2
l2.next=temp
l2=temp1
merge_two_lists(l1,l2)
end
if l1.val<l2.val
temp=l1.next
temp1=l2.next
l1=l2
l2.next=temp
l2=temp1
merge_two_lists(l1,l2)
end
if !l1.val
return l2
end
end
=end
unless(l2.val==nil)
if l1.val==l2.val
temp=l1.next
temp1=l2.next
l1=l2
l2.next=temp
l2=temp1
end
if l1.val<l2.val
temp=l1.next
temp1=l2.next
l1=l2
l2.next=temp
l2=temp1
end
if l1.val==nil
temp=l1
l1=l2
l2=temp
end
end
end