Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
时间复杂度为O(n),n代表链表总节点数
/**
* Definition for singly-linked list.
* struct ListNode {Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Note: A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?
中序遍历BST,设置一个prev指针,记录当前节点中序遍历时的前节点,如果当前节点大于prev节点的值,说明需要调整次序。用一个pair保存prev和cur
##继续来写一个自认为比较完美的atoi版本
直接上代码,关键点在处理溢出的地方!另外优化了判断的逻辑
int StrToInt(const char* str)
{
int n = 0;
int sign = 1;
int c;##KMP match
KMP算法的关键在于求算next[]数组的值,即求算模式串每个位置处的最长后缀与前缀相同的长度, 而求算next[]数组的值有两种思路,第一种思路是用递推的思想去求算,还有一种就是直接去求解(略)。
递推: