摘要: 简单题,但也思考了一会。就是pos标志下一个要写入的位置,而current标志下一个可以写入的内容。public class Solution { public int removeDuplicates(int[] A) { if (A.length == 0 || A.length == 1) return A.length; int pos = 0; int current = 0; boolean encounted = false; while (current < A.length) { if (current == 0 || A[curre... 阅读全文
posted @ 2013-09-17 22:08 阿牧遥 阅读(156) 评论(0) 推荐(0)
摘要: 简单题。public class Solution { public ListNode deleteDuplicates(ListNode head) { if (head == null) return null; if (head.next == null) return head; ListNode last = head; ListNode current = head.next; while (current != null) { if (last.val == curre... 阅读全文
posted @ 2013-09-17 21:51 阿牧遥 阅读(143) 评论(0) 推荐(0)
摘要: 树的BFS的简单变种。public class Solution { public ArrayList> zigzagLevelOrder(TreeNode root) { ArrayList> ans = new ArrayList>(); if (root == null) return ans; Queue queue = new LinkedList(); queue.offer(root); int lastLevel = 1; int thisLevel = 0; boolean... 阅读全文
posted @ 2013-09-17 21:36 阿牧遥 阅读(167) 评论(0) 推荐(0)