10 2014 档案
[Leetcode]Palindrome Number
摘要:Determine whether an integer is a palindrome. Do this without extra space.这题貌似解法挺多,直接用简单的把数倒置,没有考虑数据溢出的问题,如需解决可以把转置数设为long long即可。另外方法可以用到前后匹配、递归比较等。 ...
阅读全文
[Leetcode]Valid Palindrome
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana...
阅读全文
[Leetcode]Symmetric Tree
摘要:开始做算法题了,从AC率最高的开始做,思路一开始就找到了要用递归,但是细节上有很多需要修炼的,基础还是要打牢固。要判断是否镜像对称,只需要每次判断根节点的左子节点的左、右儿子是否相对应的等于右子节点的右、左儿子,然后递归调用isNodeSymmetric()即可。附上解法:/** * Defini...
阅读全文
[Leetcode]String to Integer (atoi) 简易实现方法
摘要:刚看到题就想用数组做,发现大多数解也是用数组做的,突然看到一个清新脱俗的解法: 1 int atoi(const char *str) { 2 3 4 5 if(*str == '\0') return 0; 6 7 int n; 8 9 ...
阅读全文
[Leetcode]Reverse Integer
摘要:核心思想:原数对10取余数赋值给新数后降一位,再把新数升一位加上下一次原数取余值,直到原数降为0。解法如下: 1 int reverse(int x) { 2 bool minus = false; 3 if(x<0) 4 { 5 ...
阅读全文
浙公网安备 33010602011771号