#include
#include
using namespace std;
//下面一个移位是一样的,>>相当于除去2,主要是要用right-left,否则对于大数据来说会产生溢出问题。切记
int binarySearch(int arr[],int len,int number)
{
int left=0;
int right=len-1;
in...
分类:
其他好文 时间:
2014-05-15 07:14:38
阅读次数:
272
当有重复元素的时候呢?
不用拍脑袋都会想到一种方法,也是所有有重复元素时的通用处理方法,维护一个set,如果这个元素没加入过就加入,加入过了的忽略掉。但是,在这道题上这个通用方法居然超时了!
怎么办?想一下为什么会这样,假设我们要排列的数字是1111112,当当前的排列中没有1时,取哪个1生成一遍,都是一样的。只有当前面的1都用过了,必须轮到这个1出场的时候,它才会有价值。更明确一点说,假设我...
分类:
其他好文 时间:
2014-05-15 05:36:25
阅读次数:
198
LeetCode-001 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2...
分类:
其他好文 时间:
2014-05-15 04:34:50
阅读次数:
293
题意:将已排序的链表中所有重复的元素移除
思路:
三个个指针,pre, cur, next
一个布尔变量is_appear,表示cur指针指向的值之前是否已经出现过
检查cur, next指向的节点的值是否相同,
相同的话,删除cur
不同的话,如果is_appear为true,删除cur,否则不删除
删除的话,只移动cur, next指针
不删除的话,要移动pre, cur, next三个指针
复杂度:时间O(n),空间O(1)...
分类:
其他好文 时间:
2014-05-15 02:54:32
阅读次数:
262
2.6内核
1>修改linux-source-2.6.31/kernel/sys.c文件,在文件末尾添加系统响应函数。函数实现如下:
asmlinkage int sys_mycall(int number)
{
printk("这是我添加的第一个系统调用");
return number;
}
2>在linux-source-2.6.31...
分类:
系统相关 时间:
2014-05-15 02:51:56
阅读次数:
382
【题目】
Implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
The function prototype shoul...
分类:
其他好文 时间:
2014-05-14 21:36:52
阅读次数:
348
题意:从一个已排序的数组中移除掉重复的元素,每个元素最多可重复两次
思路: 思路和Remove Duplicates from Sorted Array一样,不过要设置一个计数变量,表示当前值出现的次数
出现次数少于2可以加入到新数组,多于2则不可以。每次遇到一个新变量要把计数变量重新设置为1,加入新数组要加1
复杂度:时间O(n), 空间O(1)...
分类:
其他好文 时间:
2014-05-14 21:03:00
阅读次数:
262
【题目】
Determine whether an integer is a palindrome. Do this without extra space.
【题意】
题意判断一个整数是否是回文数
注意一下几点:
1. 不能用额外的空间
2. 负数不是回文数...
分类:
其他好文 时间:
2014-05-14 20:31:10
阅读次数:
298
大部分数据库都提供了窗口函数,比如RANK,ROW_NUMBER等等。MySQL这方面没有直接提供,但是可以变相的实现,我以前写了row_number的实现,今天有时间把rank的实现贴出来。这里,我用MySQL以及Python分别实现了rank窗口函数。原始表信息:t_girl=#\dgroup_concat;
Table"ytt.grou..
分类:
数据库 时间:
2014-05-14 17:04:57
阅读次数:
442
-------android培训、java培训、期待与您交流!----------MyEclipse相关知识Workspace与project切换工作空间:File---SwitchWorkspace---Other一个工作间包含多个工程,切换工作间之后,会影响里面的工程,例如快捷键什么的都要重新配置如果重新配了之后快捷键还没有用就要考虑..
分类:
其他好文 时间:
2014-05-14 17:01:52
阅读次数:
304