摘要: 问题:删除数组中和elem相等的元素,并且返回新数组大小。英语不好。。。读错题了。。class Solution {public: int removeElement(int A[], int n, int elem) { int i,j; for(int i=0;... 阅读全文
posted @ 2014-08-01 22:03 calmound 阅读(1023) 评论(0) 推荐(1) 编辑
摘要: 问题:罗马数字变为整数class Solution {public: int romanToInt(string s) { char c[10][10][10]={{"0","I","II","III","IV","V","VI","VII","VIII","IX"},{"0"... 阅读全文
posted @ 2014-08-01 21:41 calmound 阅读(896) 评论(0) 推荐(0) 编辑
摘要: 问题:一个数应该插入到有序数组的哪个位置class Solution {public: int searchInsert(int A[], int n, int target) { int i; for(i=0;i<n;i++) if(target<=A[i]) b... 阅读全文
posted @ 2014-08-01 21:26 calmound 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 问题:判断两棵二叉树是否相等class Solution {public: bool isSameTree(TreeNode *p, TreeNode *q) { if(!( (p && q && p->val==q->val) || (p==NULL && q==NULL)))... 阅读全文
posted @ 2014-08-01 21:15 calmound 阅读(641) 评论(0) 推荐(0) 编辑
摘要: 问题:将B按顺序合并到A上分析:插入排序,注意A数组为空class Solution{public: void merge(int A[], int m, int B[], int n) { int i,j; if(m==0) { ... 阅读全文
posted @ 2014-08-01 20:59 calmound 阅读(436) 评论(0) 推荐(0) 编辑
摘要: 问题:二叉树的最深深度class Solution{public: void dfs(TreeNode *root,int step,int &MAX) { if(root==NULL) { if(MAXleft,step+1); ... 阅读全文
posted @ 2014-08-01 20:41 calmound 阅读(439) 评论(0) 推荐(0) 编辑
摘要: 问题:翻转数字分析:注意初始化class Solution {public: int reverse(int x) { int y=0; while(x) { y=(y*10)+x%10; x/=10; ... 阅读全文
posted @ 2014-08-01 18:32 calmound 阅读(95) 评论(0) 推荐(0) 编辑
摘要: 问题:给你一组数一个数字出现一次,其他的数字出现两次,找出那个出现一次的数字分析:相同数字异或为0,所以将所有数字都异或后剩下的就是出现一次的数class Solution {public: int singleNumber(int A[], int n) { int sum=0... 阅读全文
posted @ 2014-08-01 18:18 calmound 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 问题:将数字转化为罗马数字分析:将所有的数字打表出来class Solution {public: string intToRoman(int num) { char c[10][10][10]={{"0","I","II","III","IV","V","VI","VII","... 阅读全文
posted @ 2014-08-01 09:18 calmound 阅读(1050) 评论(0) 推荐(0) 编辑
摘要: 问:二叉树是否存在路径和等于sum的路径,若存在输出true,否则输出false分析:递归调用二叉树,每次将上一层的val值传递给子结点并加上子节点的val,当传递到某个结点为叶子结点时,判断其val值是否等于sum错点:二叉树为空,则无论sum为多少都为false,这个容易造成RE 二叉树只... 阅读全文
posted @ 2014-08-01 07:50 calmound 阅读(1171) 评论(0) 推荐(0) 编辑