heylinart

导航

Solutions and Summay for Linked List Naive and Easy Questions

1.Remove Linked List Elements

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    /**
     * @param head a ListNode
     * @param val an integer
     * @return a ListNode
     */
public ListNode removeElements(ListNode head, int val){
		ListNode dummy = new ListNode(0);
		dummy.next = head;
		ListNode runner = dummy;
		while(runner.next != null){
			if(runner.next.val == val){
				runner.next = runner.next.next;
			}else{
				runner = runner.next;
			}
		
	}
		return dummy.next;
 }
}

 

2.Add Two Numbers

3.Delete Node in the Middle of Singly Linked List

4.Insertion Sort List

5.Merge Two Sorted Lists

6. Nth to Last Node in List

7.Partition List

8.Remove Duplicates from Sorted List

9.Remove Nth Node From End of List

10.Reverse Linked List

11.Swap Nodes in Pairs

posted on 2017-06-07 14:47  heylinart  阅读(137)  评论(0编辑  收藏  举报