Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c7017d0

Browse files
author
Ram swaroop
committed
maximum sum path: 50% done
1 parent 85680b3 commit c7017d0

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package me.ramswaroop.linkedlists;
2+
3+
import me.ramswaroop.common.SingleLinkedNode;
4+
5+
/**
6+
* Created by IntelliJ IDEA.
7+
*
8+
* @author: ramswaroop
9+
* @date: 7/15/15
10+
* @time: 12:12 AM
11+
*/
12+
public class MaximumSumLinkedList {
13+
14+
/**
15+
* Constructs a linked list that contains maximum sum path from start to end
16+
* from two linked lists starting at {@param node1} and {@param node2}.
17+
*
18+
* Example,
19+
* Input:
20+
* List1 = 1->3->30->90->120->240->511
21+
* List2 = 0->3->12->32->90->125->240->249
22+
*
23+
* Output: Following is maximum sum linked list out of two input lists
24+
* List = 1->3->12->32->90->125->240->511
25+
*
26+
* NOTE: We switch at 3 and 240 to get above maximum sum linked list
27+
*
28+
* @param node1
29+
* @param node2
30+
* @param <E>
31+
* @return
32+
*/
33+
public static <E extends Comparable<E>> SingleLinkedNode<E> maximumSumLinkedList(SingleLinkedNode<E> node1,
34+
SingleLinkedNode<E> node2) {
35+
36+
SingleLinkedNode<E> node = node1, curr1 = node1, curr2 = node2;
37+
38+
while (curr1 != null && curr2 != null) {
39+
40+
41+
curr1 = curr1.next;
42+
curr2 = curr2.next;
43+
}
44+
45+
return node;
46+
}
47+
48+
public static void main(String a[]) {
49+
50+
}
51+
}

0 commit comments

Comments
 (0)