LeetCode:Same Tree && Reverse Integer
2014-09-12 22:48
375 查看
问题描述1:
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
直接递归解决
非递归方式可以参考上文的遍历方式得出。
问题描述2:
整数翻转,例如输入:123,输出:321;
题目下面的思考挺不错的
思考1:
10100翻转后如何输出?
思考2:
翻转后溢出如何处理?当不能抛出异常时如何处理?
思考1其实是很常见的转换后精度丢失的问题,当我们舍弃开头的0时,再次转换就不会得到和原来相同的结果,如果不舍弃的话又无法用整型输出,我得到的结论是用字符串来存储转换后的数字,同时在输出时从第一个非0数开始输出。
如果是思考2的话
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
直接递归解决
非递归方式可以参考上文的遍历方式得出。
问题描述2:
整数翻转,例如输入:123,输出:321;
题目下面的思考挺不错的
思考1:
10100翻转后如何输出?
思考2:
翻转后溢出如何处理?当不能抛出异常时如何处理?
思考1其实是很常见的转换后精度丢失的问题,当我们舍弃开头的0时,再次转换就不会得到和原来相同的结果,如果不舍弃的话又无法用整型输出,我得到的结论是用字符串来存储转换后的数字,同时在输出时从第一个非0数开始输出。
如果是思考2的话
相关文章推荐
- LeetCode-Same Tree & Symmetric Tree
- LeetCode-- Same Tree & Symmetric Tree
- 【LeetCode】Maximum Depth of Binary Tree&&Same Tree
- 【LeetCode从零单排】No100 Same Tree && No101 Symmetric Tree
- <LeetCode OJ> Same Tree【100】
- Maximum Depth of Binary Tree & Same Tree & Reverse Integer
- Leetcode: Same Tree
- leetcode之Same Tree
- leetcode之same tree
- leetcode: Same Tree
- same tree & depth in the tree
- [LeetCode] Binary Tree Preorder Traversal & Binary Tree Postorder Traversal
- [LeetCode] Binary tree level order traversal I & II
- Leetcode: Same Tree 理解分析
- 【LeetCode】Convert Sorted Array to Binary Search Tree && Convert Sorted List to Binary Search Tree
- LeetCode Same Tree
- LeetCode之Same Tree
- Same Tree & Symmetric Tree
- 【leetcode】比较两棵二叉树是否相同(Same Tree)
- leetcode 65: Same Tree