二叉搜索树与双向链表:Leetcode上完全可以通过,但这里为何不行?
public class Solution { TreeNode pre, head; public TreeNode Convert(TreeNode root) { if(root == null) return null; dfs(root); head.left = pre; pre.right = head; return head; } void dfs(TreeNode cur) { if(cur == null) return; dfs(cur.left); if(pre != null) pre.right = cur; else head = cur; cur.left = pre; pre = cur; dfs(cur.right); } }
我想知道我哪里错了🤣🤣🤣🤣🤣麻烦大神指点一下;