ARTS挑战-20220331-第二周

Algorithm

在这里插入图片描述
题解
一、
因为题目有说到先序遍历,我的思路就全是先序遍历了,然后得到数组,再遍历数组
源码

public void flatten(TreeNode root) {
        List<Integer> list = new ArrayList<Integer>();
        help(root, list);
        TreeNode temp = root;
        for(int i =1; i<list.size(); i++){
            temp.left = null;
            temp.right = new TreeNode(list.get(i));
            temp = temp.right;
        }
        
    }

    // 先序遍历
    private void help(TreeNode node, List<Integer> list){
        if(node == null) {
            return ;
        }
        list.add(node.val);
        if(node.left != null) {
           help(node.left, list); 
        }
        if (node.right != null) {
           help(node.right, list);
        }      
    }

二、
实际仔细想,我左子树的最右子结点,一直是展开后的当前的右子树的前驱节点,这样我就找前驱节点就ok了啊
源码:

public void flatten(TreeNode root) {
        // 哨兵结点
        TreeNode temp = root;
        while(temp != null) {
            // 如果他的左节点不是空,
            if(temp.left != null){
                // 找到最右节点
                TreeNode next = temp.left;
                TreeNode node = next;
                while(node.right != null){
                    node = node.right;
                }
                node.right = temp.right;
                temp.right = next;
                temp.left = null;
            }
            // 下次迭代
            temp = temp.right;
        }
 }

结果
在这里插入图片描述

Review

如何code
单词
sustain : v 维持;遭受,经受;证实,证明
tedious :adj 单调乏味的
buzzword :n 流行词
句子
There’s nothing mystical about it
这一点也不神秘
Someone will always tell you you’re not a real coder
总是有人告诉你不是一个真正的程序员
Worrying about “geek cred” will slowly kill you
极客信用将会杀死你
Sticking with it is more important than the method
坚持远比方法更加重要
But this experience is so common for programmers of all skill levels that it says absolutely nothing about your intelligence, tech-savviness, or suitability for the coding life. It will happen to you as a beginner, but it will also happen to you as an experienced programmer. The main difference will be in how you respond to it.
I’ve found that a big difference between new coders and experienced coders is faith: faith that things are going wrong for a logical and discoverable reason, faith that problems are fixable, faith that there is a way to accomplish the goal. The path from “not working” to “working” might not be obvious, but with patience you can usually find it.
对与二者最大的差异是出错,相信事情出错的原因是合乎逻辑的和可发现的,出错是固定的,出错是完成目标的一种方式,这对于有工作经验和无工作经验的是明显的,有耐心才能找到它
总结
行动、坚持、相信

Tip

关于ssf框架的一点使用
它到底封装了什么?
遇见问题:在进行数据迁移工作中,需要使用多个数据源,依据以前的代码只需要在配置文件中写入数据源,然后在配置上mybatisPackage便这个包下的所有的dao都会使用这个数据源了,这是为什么呢?
追溯源码:
在这里插入图片描述
这两个接口以前有提起过:一个是注册beanDefinition的,另一个可以得到此时的环境信息,同时这个类的属性都是一些自定义的配置信息,其中可以看到mybatisPackage
然后主要的实现:
在这里插入图片描述
这里主要做:
1.在environment中找到dataSource
2.在其中找到master数据源
3.在beandefinition中注册SqlSessionFactoryBean(除主数据源外其他的会加上自己的名字)
4.注册MapperScannerConfigurer(名字同理)
解析:SqlSessionFactoryBean是工厂bean,里面会有getObject()用处得到工厂生产的对象
MapperScannerConfigurer是mybatis- spring里面提供的,有两个属性需要设置
在这里插入图片描述便可以动态的加载多数据源了
还有一个要注意的,在迁移过程中需要利用自定义注解@Table(“”)里面是表名,而我有表叫做evidence,我数据源的名字也叫这个,此时我@Table这个地方便不能注入进容器中,为啥呢?
在这里插入图片描述
可以看到这里将每个数据源的名字注册了,在一个叫IApplicationDao里面有一些增删改查的接口,可以复用。然后看自定义的是怎么使用的

在这里插入图片描述
有二个接口

ApplicationContextAware:得到上下文容器
@Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
   }
InitializingBean:初始化bean的接口,通过实现afterPropertiesSet方法

在这里插入图片描述
这里维系一个缓存,里面就应该要包含evidence的信息,但是在容器中evidence已经被上一步的IapplicationDao给注册了,所以@Table这里变不能找到
解决:给数据源改名字

Share

能扛事,管住嘴,稳住心
目前看,嘴是管住了,不说总不会错吧😂

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值