Daily Archives: January 22, 2015


[leetcode] Edit Distance

Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word: a) Insert a character b) Delete a character c) Replace a character tag: […]


[leetcode] Pow(x, n)

Pow(x, n) Implement pow(x, n). 数据结构书上的原题,也是一个经典题.直接上手写了,但第一次没过.因为没考虑到n为负数的情况.第二次AC. 时间复杂度O(logn) C++: class Solution { public: double pow(double x, int n){ return n<0?1/_pow(x,-n):_pow(x,n); } double _pow(double x, int n) { if (n == 0){ return 1; } else if(n == 1){ return x; } else{ double y = pow(x, n / 2); if(n % […]


[leetcode] Combination Sum

Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited number of times. Note: All numbers (including target) will be positive integers. Elements […]