
数据结构
JAVA开发猿
这个作者很懒,什么都没留下…
展开
-
Leetcode104. 二叉树的最大深度
1.递归解法 class Solution { public int maxDepth(TreeNode root) { if(root==null){ return 0; } int left = maxDepth(root.left); int right = maxDepth(root.right); return Math.max(left,right)+1; }原创 2020-07-27 21:48:42 · 112 阅读 · 0 评论 -
Leetcode101. 对称二叉树
递归结束条件: 都为空指针则返回 true 只有一个为空则返回 false 递归过程: 判断两个指针当前节点值是否相等 判断 A 的右子树与 B 的左子树是否对称 判断 A 的左子树与 B 的右子树是否对称 class Solution { public boolean isSymmetric(TreeNode root) { if(root==null) return true; return dfs(root.left,root.right); }原创 2020-07-24 23:35:04 · 274 阅读 · 0 评论 -
Leetcode98:验证二叉搜索树
(1)递归方法 class Solution { public boolean isValidBST(TreeNode root) { return helper(root,Long.MIN_VALUE,Long.MAX_VALUE);//表示最小值和最大值 } public boolean helper(TreeNode node,long lower,long upper){ if(node==null) return true;原创 2020-07-22 15:36:54 · 109 阅读 · 0 评论 -
Leetcode94:二叉树的中序遍历(迭代法)
public class Solution { public List < Integer > inorderTraversal(TreeNode root) { List < Integer > res = new ArrayList < > (); Stack < TreeNode > stack = new Stack < > (); TreeNode curr = root;//其实这原创 2020-07-18 01:25:38 · 306 阅读 · 0 评论 -
leetcode31:下一个排列
这道题的思路是从数组倒着查找,找到nums[i] 比nums[i+1]小的时候,就将nums[i]跟nums[i+1]到nums[nums.length - 1]当中找到一个最小的比nums[i]大的元素交换。交换后,再把nums[i+1]到nums[nums.length-1]排序,就ok了 public void nextPermutation(int[] nums) { int i = nums.length-2; while(i>=0&&nu原创 2020-07-15 22:58:14 · 110 阅读 · 0 评论 -
二维数组查找
public class ArraySearch { public static boolean find(int target,int [][] matrix){ if(matrix==null||matrix.length==0||matrix[0].length==0) { return false; } int...原创 2020-04-26 22:58:08 · 114 阅读 · 0 评论 -
数组中重复的数字
public class RepeatNumber { public static boolean duplicate(int nums[],int []duplication){ if(nums==null||nums.length==0){ return false; } for(int i=0;i<nums...原创 2020-04-25 14:50:19 · 127 阅读 · 0 评论 -
MySQL常见的三种存储引擎
1、InnoDB存储引擎 InnoDB是事务型数据库的首选引擎,支持事务安全表(ACID),其它存储引擎都 是非事务安全表,支持行锁定和外键,MySQL5.5以后默认使用InnoDB存储引擎。 InnoDB特点:支持事务处理,支持外键,支持崩溃修复能力和并发控制。如果需 要对事务的完整性要求比较高(比如银行),要求实现并发控制(比如售票),那选择InnoDB有很大的优势。 如果需要频繁的更新、删除...原创 2020-03-24 22:31:11 · 448 阅读 · 0 评论 -
回文链表
判断一个链表是否为回文链表原创 2020-03-10 23:37:54 · 112 阅读 · 0 评论 -
插入排序
void InsertSort(int arr[], int length) { for (int i = 1; i < length; i++) { int j; if (arr[i] < arr[i - 1]) { int temp = arr[i]; for (j = i - 1; j >= 0 && temp < arr[...原创 2020-03-06 23:50:06 · 153 阅读 · 0 评论 -
选择排序
原理:每一次从待排序的数据元素中选出最小(或最大)的一个元素,存放在序列的起始位置,直到全部待排序的数据元素排完。 选择排序是不稳定的排序方法 假定数组每次比较范围内第一个元素最小min,和剩下的比较,如果比假定的这个元素小,则令min为这个元素,直到找到最小的,然后交换位置,每比较一次, 就把最小的一位数找出来放数组最前面。 //选择排序 function sortSelect(arr) { ...原创 2020-03-05 23:32:10 · 213 阅读 · 0 评论 -
快速排序
public static void quickSort(int[] array, int left, int right) { if (left < right) { int pivot = array[left]; int low = left; int high = right; while (low < h...原创 2020-03-01 23:38:28 · 109 阅读 · 0 评论