menu

剑指offer 30:最小K个数

date_range 14/06/2019 00:00

基于快速排序中的Partition函数来解决这个问题。如果基于数组的第k个数字来调整,使得比第k个数字小的所有数字都位于数组的左边,比第k个数字大的所有数字都位于数组的右边。这样调整之后,位于数组中左边的k个数字就是最小的k个数字(这k个数字不一定是排序的)。

Mybatis的初使用

date_range 12/06/2019 00:00

导包

导包啊(我用的mybatis-3.4.6和mysql-connector-java 5.1.46,log4j的配置 ) 为了更好的可视化MySQL,我推荐一个链接使用Navicat for MySQL https://blog.csdn.net/wypersist/article/details/79834490 在MySQL中新建一个ssm数据库,并且创建了一个customer表,字段如下pojo类所示

编写pojo类

public class Customer {
private Integer id ;//主键字段不应该有的,在数据库中为自增的主键

private  String name;
private String gender;
private String telephone;
private  String address;
这里的字段就是和数据库中的字段要一一对应的。

剑指offer :39题

date_range 11/06/2019 00:00

平衡二叉树,是一种二叉排序树,其中每个结点的左子树和右子树的高度差至多等于1。它是一种高度平衡的二叉排序树 判断一棵树是否平衡。 普通思路,求出左右子树的高度做比较。 public class Solution { public boolean IsBalanced_Solution(TreeNode root) { if(root==null) return true; int left=Depth(root.left); int right=Depth(root.right); if(left-right>1||right-left>1) return false; else return true;

}
public int Depth(TreeNode tree){
    if(tree==null)return 0;
    int maxLeft=Depth(tree.left);
    int maxRight=Depth(tree.right);
    return maxLeft>maxRight?maxLeft+1:maxRight+1;
} } 上述代码中,做了很多不必要的操作,如果左子树下面的结点早就不平衡了,我们还往下遍历搞啥? import java.lang.Math; public class Solution {
public boolean IsBalanced_Solution(TreeNode root) {
      if(root==null||(root.left==null&&root.right==null))
          return true;
    int left=Depth(root.left);
    if(left==-1)return false;
    int right=Depth(root.right);
    if(right==-1)return false;
    if(left>0&&right>0)
    {
    if(left-right>1||right-left>1)
        return false;
    else
        return true;
    }
    return false;
    
}
public int Depth(TreeNode tree){
    if(tree==null)return 0;
    int maxLeft=Depth(tree.left);
    int maxRight=Depth(tree.right);
    return Math.abs(maxLeft-maxRight)>1?-1:Math.max(maxLeft,maxRight)+1;
    //return maxLeft>maxRight?maxLeft+1:maxRight+1;
} } 以下这段为网上借鉴。 public class Solution {
public boolean IsBalanced_Solution(TreeNode root) {
  
    return hight(root) != -1;
}
public int hight(TreeNode root){
    if(root==null){
        return 0;
    }
    int leftHight = hight(root.left);
    if(leftHight==-1){
        return -1;
    }
    int rightHight = hight(root.right);
    if(rightHight==-1){
        return -1;
    }
    if(Math.abs(leftHight-rightHight)>1){
        return -1;
    }
    return Math.max(leftHight,rightHight)+1;
} } 原文:https://blog.csdn.net/wmh1152151276/article/details/88320999

剑指offer:树的子结构

date_range 07/06/2019 00:00

判断B是否是A的树的子结构。

关于个人博客的set up

date_range 04/06/2019 00:00

以前很多人都用微博(好像没落了),技术人用csdn和博客园,好像big不够,怎么办,其实好几年前我也搭建过github的主页,但是很久没维护,故作废了。 本文内容为个人博客及jekyll writer工具写博客的指导,本人很菜,各种百度。总结一下,基本原则是要坚持,coder那必须的遇到各种问题困难,迎难而上你就会变得更强。 前人博客写教程质量参差不齐,很多人断章取义,百度给你的检索结果也很奇怪,每个人的设备不一样,网络和硬件也不同,软件环境可能差异很大。(本人用的实验室的机器:GTX1070 i7-8700 16GRAM Windows 10 +Java 1.8+Idea 2017(这些都是唬人的)正经的是Ruby ) TIM图片20190604144004.png 看到这里很多时候不知道用哪个版本,我推荐你用低的,我从2.6一直装到2.3,好像对Windows不友好。DEVELOPMENT KIT这个也得有,不然你到时候启动就发现缺少好多东西。 下载Ruby DevKit DevKit-mingw64有64位或32位可以选择,下载完成后打开,会询问解压位置(假定:C:\RubyDevKit),解压。解压后用cd C:\RubyDevKit定位到该目录下,然后运行ruby dk.rb init,初始化成功后会在目录下看到一个新文件config.yml,打开之后,添加本机ruby的安装路径,如图,然后运行ruby dk.rb install 即可完成。