题解 | #合并两群能量值#
合并两群能量值
https://www.nowcoder.com/practice/d728938f66ac44b5923d4f2e185667ec
所用知识
链表、递归
解题思路
采用简单的递归即可,见合并两个排序的链表。 https://www.nowcoder.com/share/jump/612649271690533012839
所用语言
[链接Java]
完整代码
public ListNode mergeEnergyValues (ListNode l1, ListNode l2) {
// write code here
return Merge(l1,l2);
// write code here
}
public ListNode Merge (ListNode pHead1, ListNode pHead2) {
if(pHead1 == null){
return pHead2;
}
if(pHead2 == null){
return pHead1;
}
if(pHead1.val >= pHead2.val){
pHead1.next = Merge(pHead1.next,pHead2);
return pHead1;
}else{
pHead2.next = Merge(pHead1,pHead2.next);
return pHead2;
}
// write code here
}
#合并两群能量值#