LeetCode
文章平均质量分 65
rachel_yy
这个作者很懒,什么都没留下…
展开
-
LeetCode----Invert Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };原创 2015-08-25 19:22:52 · 152 阅读 · 0 评论 -
LeetCode---Palindrome Number
思路:用sprintf转换成字符串,注意负数不是回文class Solution {public: bool isPalindrome(int x) { if(x char s[11];//int型最大为10位数 sprintf(s,"%d",x); for(int i=0,j=strlen(s)-1;i原创 2015-08-25 19:28:22 · 166 阅读 · 0 评论 -
LeetCode----Palindrome Linked List
题目描述:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?思路:利用快慢指针将链表从中间分为两段,后一段反转成新链表,依次比较两链表对应节点是否相等,直至一个链表结束; /** * Defin原创 2015-08-25 18:16:09 · 136 阅读 · 0 评论