leetcode 109 : Convert Sorted List to Binary Search Tree : <pre><code>public class Solution {
public TreeNode sortedListToBST(ListNode head) {
    if (head == null)
        return null;
    if (head.next == null)
        return new TreeNode (head.val);
    ListNode slow = head;
    ListNode fast = head;
    ListNode pre = null;
    ListNode mid = null;
    while (fast.next != null &amp;&amp; fast != null){
        pre = slow;
        fast = fast.next.next;
        slow = slow.next;
    }
    mid = slow;
    pre.next = null;
    TreeNode root = new TreeNode(slow.val);
    root.right = sortedListToBST(mid.next);
    root.left = sortedListToBST(head);

    return root;
}
</code></pre>

<p>}</p>

<p>This is my solution but it shows:
java.lang.NullPointerException</p>

<p>when i change 
<code>while (fast.next != null &amp;&amp; fast != null){</code>
to
<code>while (fast != null &amp;&amp; fast.next != null){</code>
the solution is accepted</p>

<p>i don't know the differences between them. </p>
