Implement pow(x, n).
思路:快速幂运算,需要考虑指数为负数,同时底数为0的情况,这种属于异常数据,代码里没有体现。
class Solution {
public:
double pow_abs(double x, unsigned int n)
{
if (n == 0)
{
return 1;...
分类:
其他好文 时间:
2014-08-04 21:32:48
阅读次数:
314
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution stil...
分类:
其他好文 时间:
2014-08-04 13:32:57
阅读次数:
184
这题关键注意:T可能有重复,所以得统计次数,我之前理解错了,后来参考别人代码才知道的。思路就是双指针+字符hash,具体见注释 1 class Solution { 2 public: 3 string minWindow(string S, string T) { 4 ...
题目:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution ....
分类:
编程语言 时间:
2014-08-04 10:31:57
阅读次数:
239
思路:类似于上一题,但是加了一个index数组记录结果里面已经存放的元素索引,用来判断当前的元素是否和上一个相同并且上一个是否使用过。主要为了解决重复解的问题。 1 class Solution { 2 public: 3 vector >ans; 4 vector > combin...
分类:
其他好文 时间:
2014-08-03 23:01:56
阅读次数:
213
问题:输出杨辉三角分析:对于每一行收尾都等于1,其他位置f[i,j]=f[i-1,j-1]+f[i-1,j]class Solution {public: vector > generate(int numRows) { int i,j; if(numRows==0...
分类:
其他好文 时间:
2014-08-03 22:55:26
阅读次数:
186
问题:将有序的数组中重复的数字去掉分析:由于有序所以只用和前一个比较就行class Solution {public: int removeDuplicates(int A[], int n) { int i,j; if(n==0 || n==1) return n...
分类:
其他好文 时间:
2014-08-03 17:42:35
阅读次数:
204
Give two versions of WA code:
Version 1: Runtime Error: Find the bug
class Solution {
public:
void find(const string& s, const unordered_set& dict, vector& res) {
int i, j, len = s.length();
...
分类:
其他好文 时间:
2014-08-03 15:21:27
阅读次数:
329
1版本类型1.1正式版本Enhance:增强版或者加强版属于正式版Fullversion:完全版属于正式版Release:发行版,有时间限制Upgrade:升级版Retail:零售版Plus:增强版,不过这种大部分是在程序界面及多媒体功能上增强。1.2测试版本Alphal:内部测试版Beta:外部测...
分类:
其他好文 时间:
2014-08-03 12:34:15
阅读次数:
266
Corner cases!class Solution {public: ListNode *deleteDuplicates(ListNode *head) { if (!head) return head; if (!head->next) return hea...
分类:
其他好文 时间:
2014-08-03 07:51:34
阅读次数:
237