[leetcode] Convert Sorted List to Binary Search Tree
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. tags: depth-first-search, linked list 版本一,每次取链表的中点作为root,左右分别递归调用。 我为了方便通过index取ListNode,便把list复制成了ector,却报出内存超出限额错误。尝试改进,不加vector,用时间换空间的方法。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int […]