www

导航

随笔分类 -  算法

1 2 下一页

回溯-最近公共祖先
摘要:package tree; public class CommonAncestor { /** * 定义TreeNode */ private static class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x 阅读全文

posted @ 2020-09-27 18:01 www_practice 阅读(119) 评论(0) 推荐(0)

广度遍历-二叉树最小深度
摘要:package bfs; import java.util.LinkedList; import java.util.Queue; public class TreeMinDepth { /** * 定义TreeNode */ private static class TreeNode { int 阅读全文

posted @ 2020-09-21 16:23 www_practice 阅读(172) 评论(0) 推荐(0)

滑动窗口-最小子串
摘要:package slidewindow; import java.util.HashSet; import java.util.Set; public class MinSubstring { static String minWindow(String s, String t) { // 参数校验 阅读全文

posted @ 2020-09-17 14:35 www_practice 阅读(217) 评论(0) 推荐(0)

动态规划-最短编辑距离
摘要:package dynamic; public class EditDistance { // 最短编辑距离,动态规划 static int minDistance(String s1, String s2) { int m = s1.length(), n = s2.length(); // dp 阅读全文

posted @ 2020-09-16 19:58 www_practice 阅读(220) 评论(0) 推荐(0)

回溯-全排列(重复字符)
摘要:package backtrack; import java.util.*; // 关键点:剪枝,树的每层表示字符串的某一位置,不能重复 public class Permute { private static List<String> res = new ArrayList<>(); priva 阅读全文

posted @ 2020-09-16 17:56 www_practice 阅读(188) 评论(0) 推荐(0)

滑动窗口-和为S的连续正数序列
摘要:package slidewindow;import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;public class ContinuousSequence { p 阅读全文

posted @ 2019-03-12 18:59 www_practice 阅读(220) 评论(0) 推荐(0)

数组中的逆序对
摘要:public class Solution { public int InversePairs(int[] array) { if(array==null||array.length=start&&j>=mid+1){ if(array[i]>array[j]){ copy[index--]=array[i--]; ... 阅读全文

posted @ 2019-03-12 18:36 www_practice 阅读(160) 评论(0) 推荐(0)

数字在排序数组中出现的次数
摘要:public class Solution { public int GetNumberOfK(int[] array , int k) { if(array==null||array.length==0) return 0; int first=getFirstK(array,k); int lask=getLastK(array,k); i... 阅读全文

posted @ 2019-03-12 16:08 www_practice 阅读(138) 评论(0) 推荐(0)

单例模式(Java)
摘要:注解:初试化静态的instance创建一次。如果我们在Singleton类里面写一个静态的方法不需要创建实例,它仍然会早早的创建一次实例。而降低内存的使用率。 缺点:没有lazy loading的效果,从而降低内存的使用率。 注解:定义一个私有的内部类,在第一次用这个嵌套类时,会创建一个实例。而类型 阅读全文

posted @ 2019-03-03 16:08 www_practice 阅读(123) 评论(0) 推荐(0)

最小的K个数
摘要:public class Solution { public ArrayList GetLeastNumbers_Solution(int [] input, int k) { ArrayList ret = new ArrayList(); if(k > input.length) return ret; PriorityQueue mi... 阅读全文

posted @ 2019-03-01 10:43 www_practice 阅读(143) 评论(0) 推荐(0)

数组中出现次数超过一半的数字
摘要:public int MoreThanHalfNum_Solution(int [] array) { if(array==null||array.length==0) return 0; int ret=array[0]; int times=1; for(int i=1; iarray.length/2) return ret; else return... 阅读全文

posted @ 2019-03-01 10:08 www_practice 阅读(153) 评论(0) 推荐(0)

字符串的排列
摘要:import java.util.*; public class Solution { public ArrayList Permutation(String str){ ArrayList ret = new ArrayList(); if(str!=null || str.length()>0){ helper(str.toCharArray(... 阅读全文

posted @ 2019-03-01 09:36 www_practice 阅读(132) 评论(0) 推荐(0)

二叉搜索树与双向链表
摘要:public class Solution { public TreeNode Convert(TreeNode pRootOfTree) { if(pRootOfTree == null) return null; if(pRootOfTree.left==null&&pRootOfTree.right==null) return pRootOfTree; ... 阅读全文

posted @ 2019-02-28 22:28 www_practice 阅读(98) 评论(0) 推荐(0)

二叉搜索树的后序遍历序列
摘要:public boolean VerifySquenceOfBST(int[] sequence) { if(sequence == null || sequence.length==0) return false; int start = 0, end = sequence.length-1; return helper(sequence, start, end); }... 阅读全文

posted @ 2019-02-28 19:35 www_practice 阅读(159) 评论(0) 推荐(0)

栈的压入、弹出序列
摘要:public boolean IsPopOrder(int [] pushA,int [] popA) { if(pushA == null || popA==null || pushA.length==0 || pushA.length!=popA.length) { return false; } Stack stack =... 阅读全文

posted @ 2019-02-28 18:57 www_practice 阅读(96) 评论(0) 推荐(0)

顺时针打印矩阵
摘要:public static ArrayList printMatrix(int[][] matrix) { ArrayList ret = new ArrayList(); if(matrix == null||matrix.length==0||matrix[0].length==0) return ret; int m = matrix... 阅读全文

posted @ 2019-02-28 16:45 www_practice 阅读(219) 评论(0) 推荐(0)

树的镜像
摘要:public class Solution { public void Mirror(TreeNode root) { if(root == null) return; TreeNode temp = root.left; root.left = root.right; root.right = temp; Mirror(root.... 阅读全文

posted @ 2019-02-28 14:03 www_practice 阅读(134) 评论(0) 推荐(0)

树的子结构
摘要:public class Solution { public boolean HasSubtree(TreeNode root1,TreeNode root2) { boolean ret = false; if(root1 == null || root2 == null) return ret; ret = helper(root1,root2); ... 阅读全文

posted @ 2019-02-28 13:58 www_practice 阅读(137) 评论(0) 推荐(0)

二叉树中和为某一值的路径
摘要:public class Solution { ArrayList> res = new ArrayList(); ArrayList path = new ArrayList(); public ArrayList> FindPath(TreeNode root,int target) { if (root == null) { ... 阅读全文

posted @ 2019-02-26 22:59 www_practice 阅读(143) 评论(0) 推荐(0)

从上往下打印二叉树
摘要:public ArrayList PrintFromTopToBottom(TreeNode root) { ArrayList ret = new ArrayList(); if(root==null) return ret; Queue queue = new LinkedList(); queue.offer(root); while(queue.s... 阅读全文

posted @ 2019-02-25 23:20 www_practice 阅读(133) 评论(0) 推荐(0)

1 2 下一页