国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

[LeetCode] Merge Two Sorted Lists

2019-11-15 01:11:03
字體:
供稿:網(wǎng)友
[LeetCode] Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

這道題還是很有意思的><個人覺得題讀懂后就沒啥難的了。

當然這里其實也還可以另外新弄一個listnode來輔助,這種思路更為常見,不過簡化后就發(fā)現(xiàn)不需要新建啦~

代碼如下。~

public class Solution {    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {        if(l1==null&&l2==null){            return null;        }        if(l1==null&&l2!=null){            return l2;        }        if(l2==null&&l1!=null){            return l1;        }        if(l1.val>l2.val){            l2.next=mergeTwoLists(l1,l2.next);            return l2;        }else{            l1.next=mergeTwoLists(l2,l1.next);            return l1;        }    }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 奉贤区| 灵武市| 徐水县| 普洱| 淄博市| 庄河市| 寿阳县| 桦川县| 鹤岗市| 云安县| 南康市| 牙克石市| 大姚县| 博兴县| 海原县| 陈巴尔虎旗| 驻马店市| 石棉县| 汉阴县| 饶阳县| 肇州县| 邢台市| 诏安县| 通河县| 金门县| 石楼县| 吉木萨尔县| 曲靖市| 犍为县| 涟水县| 岐山县| 肥西县| 布尔津县| 宁安市| 西藏| 彭山县| 阿尔山市| 东源县| 全州县| 宜春市| 宿州市|