leetcode114】的更多相关文章

Given a binary tree, flatten it to a linked list in-place. For example, given the following tree: 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6 给定一个二叉树,原地将它展开为链表. 例如,给定二叉树 1 / \ 2 5 / \ \ 3 4 6 将其展开为: 1 \ 2 \ 3 \ 4…
class Solution { public: void flatten(TreeNode* root) { while(root){ if(root->left){ TreeNode* pre=root->left; while(pre->right){ pre=pre->right; } pre->right=root->right; root->right=root->left; root->left=nullptr; } root=root-…
给定一个二叉树,原地将它展开为链表. 例如,给定二叉树 1 / \ 2 5 / \ \ 3 4 6 将其展开为: 1 \ 2 \ 3 \ 4 \ 5 \ 6 class Solution { public: TreeNode *last = NULL; void flatten(TreeNode* root) { if(root == NULL) return; TreeNode *r = root ->right; if(last != NULL) { last ->right = root…
Given a binary tree, flatten it to a linked list in-place. (Medium) For example,Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6 分析: 将树的问题和链表插入问题结合.对于每个节点,寻找左子树的最右端,它应该是左子树前序遍历的最后一位,也就是生成链表中,右子树根节点的前一位. 按照链表插入的方法…
题目描述 根据数独的规则Sudoku Puzzles - The Rules.判断给出的局面是不是一个符合规则的数独局面 数独盘面可以被部分填写,空的位置用字符'.'.表示 这是一个部分填写的符合规则的数独局面 Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are fill…