摘要: Reverse a linked list. For linked list 1->2->3, the reversed linked list is 3->2->1 Reverse it in-place and in one-pass 用两个指针可以做到。这种链接的在纸上先用图形+语句画好很有帮 阅读全文
posted @ 2017-09-13 10:43 jasminemzy 阅读(73) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest l 阅读全文
posted @ 2017-09-13 09:53 jasminemzy 阅读(94) 评论(0) 推荐(0) 编辑
摘要: Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). Example Given x = 123, return 321 Given x = -123, 阅读全文
posted @ 2017-09-12 21:41 jasminemzy 阅读(90) 评论(0) 推荐(0) 编辑
摘要: Given 2*n + 2 numbers, every numbers occurs twice except two, find them. Given [1,2,2,3,4,4,5,3] return 1 and 5 全异或剩两数temp=a^b,temp &= -temp, 用if(temp 阅读全文
posted @ 2017-09-12 15:42 jasminemzy 阅读(114) 评论(0) 推荐(0) 编辑
摘要: Given 3*n + 1 numbers, every numbers occurs triple times except one, find it. Given [1,1,2,3,3,3,2,2,4,1] return 4 法1:加和掩码提取位,模三,加到结果里。int 数据共有32位,针对其 阅读全文
posted @ 2017-09-12 13:54 jasminemzy 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 给出2*n + 1 个的数字,除其中一个数字之外其他每个数字均出现两次,找到这个数字。一次遍历,O(1)空间 利用异或运算的两个特性——1.自己与自己异或结果为0,2.异或满足交换律。 把所有数字异或起来就是答案。 public class Solution { /* * @param A: An 阅读全文
posted @ 2017-09-12 13:33 jasminemzy 阅读(99) 评论(0) 推荐(0) 编辑
摘要: Given an input string, reverse the string word by word. For example,Given s = "the sky is blue",return "blue is sky the". What constitutes a word?A se 阅读全文
posted @ 2017-09-11 13:42 jasminemzy 阅读(167) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two n 阅读全文
posted @ 2017-09-09 15:37 jasminemzy 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 1. 小心处理l1和l2其中有一个先null了的情况,可以digit1 = l1 == null ? 0 : l1.val;2. 还有小心l1后移的情况,如果l1已经是null了,那就不能后移了,所以要l1 = l1 == null ? l1 : l1.next;3. 小心后面每次加的时候要多加个c 阅读全文
posted @ 2017-09-09 15:36 jasminemzy 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 原文链接:http://www.runoob.com/java/java-override-overload.html Java 重写(Override)与重载(Overload) 重写(Override) 重写是子类对父类的允许访问的方法的实现过程进行重新编写, 返回值和形参都不能改变。即外壳不变 阅读全文
posted @ 2017-09-05 13:04 jasminemzy 阅读(292) 评论(0) 推荐(0) 编辑