力扣面试150题-- 翻转二叉树

Day 41

题目描述

做法

java 复制代码
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public TreeNode invertTree(TreeNode root) {
        if(root==null){
            return null;
        }
        TreeNode left=invertTree(root.left);
        TreeNode right=invertTree(root.right);
        TreeNode x=left;
        root.left=right;
        root.right=left;
        return root;
    }
}
相关推荐
大佬,救命!!!1 天前
算法实现迭代2_堆排序
数据结构·python·算法·学习笔记·堆排序
Dream it possible!1 天前
LeetCode 面试经典 150_栈_简化路径(53_71_C++_中等)(栈+stringstream)
c++·leetcode·面试·
爱和冰阔落1 天前
【C++继承下】继承与友元 / static 菱形继承与虚继承 组合的详解分析
c++·面试·腾讯云ai代码助手
程序员阿鹏1 天前
49.字母异位词分组
java·开发语言·leetcode
天桥下的卖艺者1 天前
R语言手搓一个计算生存分析C指数(C-index)的函数算法
c语言·算法·r语言
Espresso Macchiato1 天前
Leetcode 3715. Sum of Perfect Square Ancestors
算法·leetcode·职场和发展·leetcode hard·树的遍历·leetcode 3715·leetcode周赛471
草莓熊Lotso1 天前
《C++ Stack 与 Queue 完全使用指南:基础操作 + 经典场景 + 实战习题》
开发语言·c++·算法
敲上瘾1 天前
单序列和双序列问题——动态规划
c++·算法·动态规划
太过平凡的小蚂蚁1 天前
策略模式:让算法选择像点菜一样简单
算法·策略模式
Simon_He1 天前
最强流式渲染,没有之一
前端·面试·ai编程