标签:style init ffffff 思路 合并 == 代码 merge sts
尴尬:
尴尬的思路:从数组中找出最小值的节点。
尴尬的代码:
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public int findMin(ListNode[] lists){ int min = 0x7ffffff; int index = -1; for( int i=0; i < lists.length; ++i ){ if( lists[i] == null ) continue; if( lists[i].val < min ){ min = lists[i].val; index = i; } } return index; } public ListNode mergeKLists(ListNode[] lists) { ListNode head = new ListNode(0); ListNode tmp =head; int i; while( true ){ i = findMin(lists); if( i == -1 ) break; tmp.next = lists[i]; tmp = lists[i]; lists[i] = lists[i].next; } return head.next; } }
标签:style init ffffff 思路 合并 == 代码 merge sts
原文地址:https://www.cnblogs.com/lijins/p/10148570.html