摘要:
partition函数是快排的核心部分它的目的就是将数组划分为pivot两部分,或者是=pivot其实现方法大体有两种,单向扫描版本和双向扫描版本,但是具体到某个版本,其实现方法也是千差万别,参差不齐。本着严谨治学的态度,我将目前所接触的所有实现列举出来,并作出比较。除了伪代码,我也会给出相应的C&... 阅读全文
摘要:
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Note:Do not modify the linked list.Follow up:Can you sol... 阅读全文
摘要:
Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"click to show corner cas... 阅读全文
摘要:
Implement pow(x,n).Subscribeto see which companies asked this question利用依次消去二进制位上的1,来进行计算double myPow(double x, int n) { double ans = 1; unsigne... 阅读全文
摘要:
Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor... 阅读全文
摘要:
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-nega... 阅读全文
摘要:
再次优化快速排序,三数中值取理想的pivot,三向切分忽略与pivot相同的元素,小数组转插入排序(唯一不足递归实现,不过是尾递归,编译器可以优化掉)代码很短,而且可读性很好,记录于此以供参考const int cutoff = 3;void insertSort(int a[], int len)... 阅读全文
摘要:
void insertSort(int a[], int len){ for (int i = 1; i = 0; --j) { if (a[j] > 1; if (a[left] > a[center]) swap(&a[left], ... 阅读全文
摘要:
Given an array of integers and an integerk, find out whether there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and the differe... 阅读全文
摘要:
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the arr... 阅读全文