Algorithm
合并K個(gè)排序鏈表
合并 k 個(gè)排序鏈表揩尸,返回合并后的排序鏈表。請(qǐng)分析和描述算法的復(fù)雜度。
示例:輸入:
[
1->4->5,
1->3->4,
2->6
]
輸出: 1->1->2->3->4->4->5->6
解題思路:鏈表兩兩合并
public ListNode mergeKLists(ListNode[] lists) {
ListNode result = null;
for (int i = 0 ; i<lists.length;i++){
result = twoMergeLists(result,lists[i]);
}
return result;
}
public ListNode twoMergeLists(ListNode node1, ListNode node2) {
if(node1 == null){
return node2;
}
if(node2 == null){
return node1;
}
ListNode head = new ListNode(0);
ListNode tail = head;
ListNode item1 = node1;
ListNode item2 = node2;
while(item1 != null && item2 != null){
if(item1.val <= item2.val ){
tail.next = item1;
item1 = item1.next;
}else{
tail.next = item2;
item2 = item2.next;
}
tail = tail.next;
}
if(item1 != null ){
tail.next = item1;
}
if(item2 != null ){
tail.next = item2;
}
return head.next;
}
Review
具有產(chǎn)品思維的軟件工程師
1、積極主動(dòng)對(duì)待產(chǎn)品理念或觀點(diǎn)
2、對(duì)商業(yè)迎变、用戶和數(shù)據(jù)感興趣
3、好奇和對(duì)為什么感興趣
4驼壶、良好的溝通能力和與非工程師的良好關(guān)系
5氏豌、提前提供產(chǎn)品和工程的這種方案
6喉酌、務(wù)實(shí)的處理邊界情況
7热凹、快速的產(chǎn)品驗(yàn)證周期
8、端對(duì)端的產(chǎn)品特性
9泪电、強(qiáng)烈的產(chǎn)品本能通過反復(fù)的循環(huán)學(xué)習(xí)
Tip
1般妙、好用的Excel插件easyExcel
2、使用開源框架相速,首先要熟悉他的文檔碟渺,業(yè)務(wù)邏輯可以根據(jù)文檔中的功能組合實(shí)現(xiàn)
3、使用框架要了解他的原理突诬,必要的時(shí)候可以查看源碼苫拍,如springboot要清楚的明白自動(dòng)配置如何實(shí)現(xiàn)
4芜繁、說話和做事要理清思路,如一二三绒极,最后總結(jié)