KMP算法的实现:#include #include #include int strStr(char* haystack, char* needle) { if (haystack == NULL || needle == NULL) return -1; if (nee...
分类:
其他好文 时间:
2015-05-29 11:41:11
阅读次数:
89
题目描述
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without...
分类:
其他好文 时间:
2015-05-28 23:16:30
阅读次数:
173
Regular Expression Matching
题目:
Implement regular expression matching with support for ‘.’ and ‘*’.
‘.’ Matches any single character.
‘*’ Matches zero or more of the preceding element.
Th...
分类:
其他好文 时间:
2015-05-28 21:31:52
阅读次数:
197
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The si...
分类:
其他好文 时间:
2015-05-28 09:21:06
阅读次数:
115
String to Integer (atoi)
题目:
Implement atoi to convert a string to an integer.
Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourse...
分类:
其他好文 时间:
2015-05-27 15:50:24
阅读次数:
134
完全抄答案class TrieNode { // Initialize your data structure here. // ref http://www.programcreek.com/2014/05/leetcode-implement-trie-prefix-tree-jav...
分类:
其他好文 时间:
2015-05-27 07:26:48
阅读次数:
195
Pow(x, n)
Implement pow(x, n).
解题思路:
这里n是整数,注意可能是负数,因此需要先将其转化成正数。若直接用循环的方法做,会产生超时错误。我们可以这么做。比如求2^6,我们需要求2^(2*3)=4^3=4*4^2,这样时间复杂度为O(logn)。
注意几个特殊的情况,当n==1时,返回x本身,当n==0时,返回1,当n为偶数时,返回myPow(x*x...
分类:
其他好文 时间:
2015-05-27 01:03:28
阅读次数:
309
Fromcomp.lang.objective-C FAQ listing: "What if multiple categories implement the same method?Then the fabric of the Universe as we know it ceases to ...
分类:
其他好文 时间:
2015-05-26 12:26:34
阅读次数:
195
/*
Description:
The strstr function locates the firstoccurrence in the string pointed to by s1 of the sequence of characters(excluding the terminatingnull character)in the string pointed to by s2...
分类:
其他好文 时间:
2015-05-24 17:29:24
阅读次数:
135
1 Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.
因为这里都是整数,可以直接采用二分法求解int mySqrt(int x) {
if (x <= 1) return x;
int begin = 1, end =x, mid = 0;
while (begin...
分类:
编程语言 时间:
2015-05-24 13:00:28
阅读次数:
173