DataStructure
DataStructure copied to clipboard
Time complexity of merge sort
hello, the Time complexity of merge sort maybe O(nlogn), right?
Yeah, the complexity of Merge Sort is always O(nlogn). And, it is independent of initial sequence.
链表类里的删除重复元素对于连续的重复元素不能删除,例如3,2,2,2,4,4,这样修改就对了 Node<E> cur = head.next; while (cur != null) { Node<E> temp = cur; while ( temp.next != null) { if (cur.data.equals(temp.next.data)) { Node<E> DupNode = temp.next; temp.next = DupNode.next; DupNode.next = null; size--; } else { temp = temp.next; } } cur = cur.next; }
o(n^2) right?