【LeetCode】 109. Convert Sorted List to Binary Search Tree C语言
来源:互联网 发布:mac mp3编辑软件 编辑:程序博客网 时间:2024/06/12 00:55
LeetCode解题心得,欢迎交流! 第三日
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; *//** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode *toBST(struct ListNode *head,struct ListNode *tail) { if(head==tail) return NULL; struct ListNode *fast=head; struct ListNode *slow=head; while(fast!=tail && fast->next!=tail) // 这样写是错的while(fast!=NULL && fast->next!=NULL) { fast=fast->next->next; slow=slow->next; } struct TreeNode *tree_head=(struct TreeNode *)malloc(sizeof(struct TreeNode)); tree_head->val = slow->val; tree_head->left = toBST(head,slow); tree_head->right=toBST(slow->next,tail); return tree_head;}struct TreeNode* sortedListToBST(struct ListNode* head) { if(head == NULL) return NULL; return toBST(head,NULL); }
0 0
- 【LeetCode】 109. Convert Sorted List to Binary Search Tree C语言
- LeetCode 109. Convert Sorted List to Binary Search Tree
- [LeetCode]109.Convert Sorted List to Binary Search Tree
- 109.Convert Sorted List to Binary Search Tree Leetcode Python
- [Leetcode] 109. Convert Sorted List to Binary Search Tree
- LeetCode --- 109. Convert Sorted List to Binary Search Tree
- [leetcode] 109.Convert Sorted List to Binary Search Tree
- 109. Convert Sorted List to Binary Search Tree LeetCode
- [leetcode] 109. Convert Sorted List to Binary Search Tree
- Leetcode 109. Convert Sorted List to Binary Search Tree
- [LeetCode]109. Convert Sorted List to Binary Search Tree
- LeetCode *** 109. Convert Sorted List to Binary Search Tree
- LeetCode 109. Convert Sorted List to Binary Search Tree
- LeetCode - 109. Convert Sorted List to Binary Search Tree
- Leetcode 109. Convert Sorted List to Binary Search Tree
- [leetcode] 109. Convert Sorted List to Binary Search Tree
- [LeetCode] 109. Convert Sorted List to Binary Search Tree
- Leetcode-109. Convert Sorted List to Binary Search Tree
- 170416 汇编-标志寄存器:SF、CF、OF
- Android,6.0权限,简单实现,好用的框架
- HDU
- 华为oj 成绩排序java编码
- JS中的forEach、$.each、map的区别
- 【LeetCode】 109. Convert Sorted List to Binary Search Tree C语言
- 编译完Qt5.8.0没有报错
- cp/scp 命令
- java1.5中{@inheritDoc}的运用
- Glide使用详解(一)
- 会话控制(基于Coookie,session和Url)
- 青蛙的约会
- docker 常用命令
- sublime text 3 快捷键 pc mac 大全