示例代码(1)
decimal Factorial(int n)
{
if (n == 0)
return 1;
else
return n * Factorial(n - 1);
}
【分析】
阶乘(factorial),给定规模 n,算法基本步骤执行的数量为 n,所以算法复杂度为 O(n)。
示例代码(2)
int FindMaxElement(int[] array)
{
int max = array[0]...
分类:
编程语言 时间:
2015-08-02 21:43:05
阅读次数:
174
Given two strings s and t, write a function to determine if t is an anagram of s.
For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.
Note:
You may a...
分类:
其他好文 时间:
2015-08-02 21:34:46
阅读次数:
104
class Solution {public: string countAndSay(int n) { string res; if(n<=0) return res; res += '1'; for(int i=0;i<n-1;...
分类:
其他好文 时间:
2015-08-02 21:32:48
阅读次数:
111
class Solution {public: int search(vector& nums, int target) { return rotate_search(nums,0,nums.size()-1,target); } int rotate_search(...
分类:
其他好文 时间:
2015-08-02 21:24:04
阅读次数:
117
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next...
分类:
其他好文 时间:
2015-08-02 19:47:38
阅读次数:
107
函数的重载:
# include
void swap(void)
{
printf("呵呵!\n");
return;
}
void swap(int i, int j)
{
printf("哈哈!\n");
return;
}
int main(void)
{
swap();
swap(1, 2); //函数名相同,形参个数不同,也不是同一个函数。
int i ...
分类:
编程语言 时间:
2015-08-02 18:22:32
阅读次数:
151
图片处理如何处理图片
拿到网页
使用正则表达式匹配
使用urlretrieve下载图片
import re
import urllib2
import urllibdef getContext(url):
'''
获取html
'''
html = urllib2.urlopen(url) return html.read()def getPicture(htm...
分类:
其他好文 时间:
2015-08-02 18:21:29
阅读次数:
100
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 in...
分类:
其他好文 时间:
2015-08-02 18:20:21
阅读次数:
112
总结一下指针与函数和数组的关系及相关练习。
传统数组的缺点:
# include
int main(void)
{
//数组的定义
int len = 5;
int a[len]; //错误,数组的长度必须直接指定,且不能更改。
int b[5]; //正确。
return 0;
}
确定一个数组需要几个参数:
# include
//本函数功能是输出任意一...
分类:
编程语言 时间:
2015-08-02 18:20:03
阅读次数:
164
思想
定义头尾两个指针
交换头尾指针的数据
//字符串翻转
char *strrev(char *str){
//判断字符是否为null或是空字符串
if(str == NULL || str == '\0') {
return str;
}
//定义char数组指针
char *start = str;
char...
分类:
其他好文 时间:
2015-08-02 18:19:11
阅读次数:
123