摘要:
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function ... 阅读全文
摘要:
根据binary search,每次我们都可以切掉一半的数据,所以算法的时间复杂度是O(logn),空间复杂度是O(1)。 阅读全文
摘要:
层次递进法 复杂度 时间 O(N) 空间 O(1) 阅读全文
摘要:
复杂度 时间 O(N) 空间 O(N) 思路 相当于是Level Order遍历二叉树。通过一个Queue来控制每层的遍历,注意处理该层最后一个节点的特殊情况。此方法同样可解第二题。 没想到的方法:因为guarantee了是perfect binary tree 层次递进法 复杂度 时间 O(N) 阅读全文
摘要:
String s1 = "";means that the emptyStringis assigned tos1. In this case,s1.length()is the same as"".length(), witch will yield0as expected.String s2 =... 阅读全文
摘要:
Object copyAnobject copyis an action in computing where a data object has itsattributescopied to another object of the same data type. Anobjectis a co... 阅读全文
摘要:
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2-... 阅读全文
摘要:
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy ... 阅读全文
摘要:
记得Insert Sort List, 那个复杂度是O(N^2)的,这里要求O(nlogn),所以想到merge sort, 需要用到Merge Two Sorted List的方法(我写的merge函数) 第二遍代码:所以mergesort不好写在于它是一个递归里嵌套另一个递归,第一个递归不停地用 阅读全文