题意:给个单链表,判断是否为回文。思路:有点BT,处理不好都是死循环。一般思路是,二分查找中心点,根据奇偶个元素,反置前半部分,再判断是否回文,再恢复前半部分。步骤: (1)在二分查找中心点时判断顺便反置前半部分链表。 (2)对奇偶数处理好剩下的工作。这是重点 (3)两个指针来判断是否回文。 ...
分类:
其他好文 时间:
2015-07-11 11:50:00
阅读次数:
90
POJ2533裸的LIS,时间复杂度为O(n^2) 1 #include 2 #include 3 using namespace std; 4 const int MAXN=1000+5; 5 int a[MAXN]; 6 int dp[MAXN]; 7 int n,ans; 8 9 int m....
分类:
其他好文 时间:
2015-07-11 11:46:32
阅读次数:
93
Equal Sum Partitions
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 551 Accepted Submission(s): 409
Problem Description
An equal su...
分类:
其他好文 时间:
2015-07-10 15:18:36
阅读次数:
106
一开始自己搞,写了半天还是成了四重循环,虽然没个循环依次递减,而且二分查找,但是依然超时,唉,看来还是太弱啊,思路过于单一。
搜了一个题解,是用递推构造了两个二维数组,利用题目的特点维护了两个变量,然后只需要枚举q和r就可以了。
l[i][j]表示下标小于j且值比a[i]大的数中最小的值的下标。 r[i][j]表示下标大于j且值比a[i]小的数中最大的值的下标。
我们枚举q和r ,那么显然可...
分类:
其他好文 时间:
2015-07-09 21:30:58
阅读次数:
149
Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume...
分类:
其他好文 时间:
2015-07-09 18:07:25
阅读次数:
125
Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.
Your algorithm's runtime complexity must be in the order of O(log n).
If...
分类:
其他好文 时间:
2015-07-09 14:41:20
阅读次数:
87
1. HashMap的数据结构
数据结构中有数组和链表来实现对数据的存储,但这两者基本上是两个极端。
数组
数组存储区间是连续的,占用内存严重,故空间复杂的很大。但数组的二分查找时间复杂度小,为O(1);数组的特点是:寻址容易,插入和删除困难;
链表
链表存储区间离散,占用内存比较宽松,故空间复杂度很小,但时间复杂度很大,达O(N)。链表的特点是:寻址困难...
分类:
其他好文 时间:
2015-07-09 11:28:07
阅读次数:
183
思路:应该是用二分查找分别找到该数字第一次和最后一次出现的位置,相减即可。O(logn)int findLeft(int a[], int n, int num){ int l = 0, r = n - 1; while(l = 0 && a[l] == num) //找左边界 ...
分类:
编程语言 时间:
2015-07-08 22:10:48
阅读次数:
161