Package leetcode

Examples of leetcode.ListNode


import leetcode.ListNode;

public class Solution2_1 {
    public ListNode deleteDup(ListNode head) {
        ListNode first = head;
        while (first != null) {
            ListNode pre = first;
            ListNode cur = first.next;
            while(cur != null) {
                if (cur.val == first.val)
                    pre.next = cur.next;
                else
                    pre = cur;
View Full Code Here


        }
        System.out.println();
    }

    public ListNode construct(int[] arr) {
        ListNode head = null;
        ListNode cur  = null;
        for (int x : arr) {
            if (cur == null) {
                head = cur = new ListNode(x);
            } else {
                cur.next = new ListNode(x);
                cur = cur.next;
            }
        }
        return head;
    }
View Full Code Here

        return head;
    }

    public static void main(String args[]) {
        Solution2_1 so = new Solution2_1();
        ListNode head = so.construct(new int[]{});
        so.print(so.deleteDup(head));
        head = so.construct(new int[]{1, 2, 3, 3 ,3, 2, 1, 2});
        so.print(so.deleteDup(head));
        head = so.construct(new int[]{1});
        so.print(so.deleteDup(head));
View Full Code Here

import leetcode.ListNode;

public class Solution2_5 {
    public ListNode find(ListNode head) {
        ListNode n1 = head;
        ListNode n2 = head;
        boolean find = false;

        while (n2 != null && n2.next != null) {
            n1 = n1.next;
            n2 = n2.next.next;
View Full Code Here

* To change this template use File | Settings | File Templates.
*/
public class ReverseK {
    public class Solution {
        public ListNode reverseKGroup(ListNode head, int n) {
            ListNode senti = new ListNode(-1);
            senti.next = head;
            ListNode cur = senti;

            while (cur.next != null) {
                ListNode pre = cur;
                ListNode tail = cur.next;
                cur = cur.next;
                ListNode next = cur.next;

                int count = 1;
                for (int i = 1; i < n; i ++) {
                    if (next == null)
                        break;
                    count = i + 1;
                    ListNode tmp = next.next;
                    next.next = cur;
                    cur = next;
                    next = tmp;
                }

View Full Code Here

TOP

Related Classes of leetcode.ListNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.