Convert Sorted List to Binary Search Tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

A height balanced BST : a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 
Example :


Given A : 1 -> 2 -> 3
A height balanced BST  :

      2
    /   \
   1     3

Solution:

Time: O(n)

/**
 * Definition for binary tree
 * class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     public int val;
 *     public ListNode next;
 *     ListNode(int x) { val = x; next = null; }
 * }
 */
public class Solution {
    private ListNode findMid(ListNode node) {
        ListNode slow = node;
        ListNode fast = node;
        while (fast != null && fast.next != null) {
            ListNode prev = slow;
            slow = slow.next;
            fast = fast.next.next;
            if (fast == null || fast.next == null) {
                prev.next = null;
            }
        }
        return slow;
    }
    
    public TreeNode sortedListToBST(ListNode a) {
        if (a == null) return null;
        ListNode mid = findMid(a);
        TreeNode root = new TreeNode(mid.val);
        if (mid == a) return root;
        root.left = sortedListToBST(a);
        if (mid != null) {
            root.right = sortedListToBST(mid.next);
        }
        return root;
    }
}