原题链接:https://oj.leetcode.com/problems/powx-n/
1. 首先处理特殊情况,比如0,1,-1
2. 关于普遍情况,考虑x^7 = x^(4 + 2 + 1),注意4,2,1都是2的n次方,所以转化为((x ^ 2) ^ 2) * (x ^ 2) * (x)。更加直观来看,我们可以将指数7看为二进制表示111,每一位从右到左对应的是x ^ 4,x ...
分类:
其他好文 时间:
2015-01-29 17:48:53
阅读次数:
130
原题链接:https://oj.leetcode.com/problems/count-and-say/
这道题其实考的还是细心了,外层循环n,内存循环当前字符长度。
class Solution {
public:
string countAndSay(int n) {
string res = "";
if (n < 0) retur...
分类:
其他好文 时间:
2015-01-29 17:36:51
阅读次数:
105
题目链接:https://oj.leetcode.com/problems/sort-colors/
题目信息:
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the ...
分类:
其他好文 时间:
2015-01-29 09:28:58
阅读次数:
109
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'24: Swap Nodes in Pairshttps://oj.leetcode.com/problems/swap-nodes-in-pairs/Given a linked...
分类:
编程语言 时间:
2015-01-29 01:23:35
阅读次数:
178
https://oj.leetcode.com/problems/word-break-ii/Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is ...
分类:
其他好文 时间:
2015-01-29 00:00:13
阅读次数:
415
题目连接:http://www.codechef.com/problems/ANUMLA题意:给一个序列所有子集和(2^n个子集),复原这个序列。。。如:0 1 1 2 2 3 3 4原序列为1 1 2分析:每次找出最小的那个元素,再删除掉可能由该元素相加得到的元素,如上面那个例子,将所有可能相加得...
分类:
其他好文 时间:
2015-01-28 06:07:47
阅读次数:
148
题目链接:[Two Sum](https://oj.leetcode.com/problems/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 th...
分类:
其他好文 时间:
2015-01-27 23:36:58
阅读次数:
356
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'23: Merge k Sorted Listshttps://oj.leetcode.com/problems/merge-k-sorted-lists/Merge k sort...
分类:
编程语言 时间:
2015-01-27 23:08:46
阅读次数:
244
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'22: Generate Parentheseshttps://oj.leetcode.com/problems/generate-parentheses/Given n pair...
分类:
编程语言 时间:
2015-01-27 23:04:14
阅读次数:
162
原题链接:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/
很简单的题,维持一个front标志和prev维持之前的值,边扫边比较。
class Solution {
public:
int removeDuplicates(int A[], int n) {
if ...
分类:
其他好文 时间:
2015-01-27 18:34:54
阅读次数:
190