摘要: 1 class Solution { 2 public: 3 bool isPalindrome(string s) { 4 if(s=="") return true; 5 if(s.length()==1) return true; //单个字符,对称... 阅读全文
posted @ 2014-11-08 21:47 xcw0754 阅读(350) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(i... 阅读全文
posted @ 2014-11-08 21:36 xcw0754 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 int r=0,init=x; 5 if(init==0) return true; 6 if(init<0) ... 阅读全文
posted @ 2014-11-07 13:52 xcw0754 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome number"时翻到此文章,经过少量修改后如下。 回文数是数学界中的一种有趣的现象。比如121就是一个回文数。回文数 阅读全文
posted @ 2014-11-07 13:24 xcw0754 阅读(1453) 评论(0) 推荐(0) 编辑
摘要: 思路:主要判断左子树与右子树。在判断左时,循环下去肯定会到达叶子结点中最左边的结点与最右边的结点比较。到了这一步因为他们都没有左(右)子树了,所以得开始判断这两个结点的右(左)子树了。当某个结点对称了,它的左子树也对称了,右子树也对称了,那才是真的对称了。C++ 1 /** 2 * Definit... 阅读全文
posted @ 2014-11-05 13:26 xcw0754 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 using namespace std; 4 int ato(const char *str) { 5 int i=0,e=0,s=0; 6 int max=2147483647,min=-2147483648; 7 in... 阅读全文
posted @ 2014-11-03 22:09 xcw0754 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 int main() 4 { 5 int a,b,n; 6 int i; 7 int f[52]={0}; 8 f[0]=1; 9 f[1]=1;10 while(scanf("%d %d %d",... 阅读全文
posted @ 2014-10-28 23:05 xcw0754 阅读(440) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 char a[1000][16]; 4 int b[1000]={0}; 5 int main() 6 { 7 int n,i,j,k,max,loc; 8 while(scanf("%d",&n)!=EOF&&n!=0){ 9 ... 阅读全文
posted @ 2014-10-26 14:04 xcw0754 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 int main(){ 3 int i,t,j,n,x; 4 int start,end,temp,max,sum; 5 scanf("%d",&t); 6 for(i=0;i=max){15 ... 阅读全文
posted @ 2014-10-26 13:49 xcw0754 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #define MAX 1009 4 int main() 5 { 6 char a[MAX]={0},b[MAX]={0}; 7 int n,i,len1,len2,j=0,z=0,r=0,k=0; 8 char *p=... 阅读全文
posted @ 2014-10-26 13:42 xcw0754 阅读(141) 评论(0) 推荐(0) 编辑