public TreeNode sortedListToBST(ListNode head) {
        // Start typing your Java solution below
        // DO NOT write main() function
        if(head == null) return null;

    	if(head.next == null) return new TreeNode(head.val);

    	ListNode preSlow = null, slow = head, fast = head;
    	while(fast != null && fast.next != null){
    		preSlow = slow;
    		slow = slow.next;
    		fast = fast.next.next;
    	}

    	TreeNode root = new TreeNode(slow.val);

    	preSlow.next = null;
    	root.left = sortedListToBST(head);
    	root.right = sortedListToBST(slow.next);

    	return root;

        
    }