摘要: 注意,如果用的方法是翻转整个链表,那么链表都被改变了。就无法做了。此外注意fast.next.next!= null;不然也会报错。要保证后面的比前面的少。答案:public static boolean isPalindrome(ListNode head){ if(... 阅读全文
posted @ 2015-12-18 11:37 仔细思考一切 阅读(158) 评论(0) 推荐(0)
摘要: public ListNode detectCycle(ListNode head) { ListNode fast = head; ListNode slow = head; int flag = 0; ListNode intersection = nu... 阅读全文
posted @ 2015-12-18 09:18 仔细思考一切 阅读(163) 评论(0) 推荐(0)
摘要: 这里,注意如果是尾结点,那么无解。public class Solution {public void deleteNode(ListNode node) {//利用李代桃僵// // if(node.next == null)// // {// // node = null;//error: no... 阅读全文
posted @ 2015-12-17 23:16 仔细思考一切 阅读(186) 评论(0) 推荐(0)
摘要: 这里是用了自己的方法,和书本不一样。import java.util.HashSet;import java.util.Set;class ListNode{ int val; ListNode next; ListNode(int x){ val = x; }... 阅读全文
posted @ 2015-12-17 23:14 仔细思考一切 阅读(179) 评论(0) 推荐(0)
摘要: 答案,注意,一种是递归,另一种是迭代,那么巧妙利用双指针:迭代: public static LinkedListNode nthToLast(LinkedListNode head, int n) { LinkedListNode p1 = head; Linke... 阅读全文
posted @ 2015-12-17 12:31 仔细思考一切 阅读(180) 评论(0) 推荐(0)
摘要: 注意,题目要求要保持两部分的相对顺序,所以,用交换是不行的。import java.util.HashSet;import java.util.Set;class ListNode{ int val; ListNode next; ListNode(int x){ v... 阅读全文
posted @ 2015-12-17 11:15 仔细思考一切 阅读(277) 评论(0) 推荐(0)
摘要: 分成两种,1种开了额外空间,临时缓冲区,一种没有开import java.util.HashSet;import java.util.Set;class ListNode{ int data; ListNode next;}public class Solution{ public... 阅读全文
posted @ 2015-12-16 23:24 仔细思考一切 阅读(152) 评论(0) 推荐(0)
摘要: import java.util.*; public class Transform { public int[][] transformImage(int[][] matrix, int n) { // write code here n = matrix.... 阅读全文
posted @ 2015-12-16 17:36 仔细思考一切 阅读(769) 评论(0) 推荐(0)
摘要: import java.util.*; public class Zipper { public String zipString(String str) { // write code here if(str.length() == 0 ) return str; ... 阅读全文
posted @ 2015-12-16 17:35 仔细思考一切 阅读(228) 评论(0) 推荐(0)
摘要: import CtCILibrary.AssortedMethods;public class Question { // Assume string has sufficient free space at the end public static void replaceSpace... 阅读全文
posted @ 2015-12-16 17:33 仔细思考一切 阅读(232) 评论(0) 推荐(0)