https://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/
Http://fisherlei.blogspot.com/2013/01/leetcode-convert-sorted-list-to-binary.html
http://blog.csdn.net/worldwindjp/article/details/39722643
/** * definition for singly-linked list. * public class listnode { * int val; * ListNode Next; * listnode (int x) { val = x; next = null; } * } *//** * Definition for binary tree * public class treenode { * int val; * TreeNode left; * TreeNode right; * treenode (int x) { val = x; } * } */public class solution { public treenode sortedlisttobst (ListNode head) { // option A: treenode root = buildtop2buttom (head, NULL); return root; } ////////////////////////// // Option A: Top to bottom // // unlike sorted array, no random access. // but we still can follow the Same strategy that: // given head, find the mid. // o (n log n) private TreeNode Buildtop2buttom (listnode start, listnode end) { if (start == null | | start == end) return null; if (start.next == end) return new treenode (Start.val); listnode mid = findmid (start, end); treenode root = New treenode (Mid.val); root.left = Buildtop2buttom (Start, mid); root.right = Buildtop2buttom (mid.next, end); return root; } // find the mid node from ' start ' (inclusive)  TO  ' End ' (exclusive) private listnode findmid (Listnode start, listnode end) { listnode toreturn = null; ListNode s1 = start; ListNode s2 = start; while (s2 != null && s2 != end) { toreturn = s1; s1 = s1.next; s2 = s2.next; if (s2 == null | | s2 == end) s2 = null; else s2 = s2.next; } return toreturn; }}
[leetcode]109 Convert Sorted List to Binary Search Tree