![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
wang_nian
不以物喜 不以己悲 生于忧患 死于安乐
展开
-
二分查找
正常实现 Input : [1,2,3,4,5] key : 3 return the index : 2 public int binarySearch(int[] nums, int key) { int l = 0, h = nums.length - 1; while (l <= h) { int m = l + (h - l) / 2; if (nums[m] == key) { return m;原创 2020-12-27 14:28:48 · 99 阅读 · 0 评论 -
二叉树的遍历
1.1、中序遍历,非递归,用栈 class Solution { public List<Integer> inorderTraversal(TreeNode root) { if(root == null) return new ArrayList<>(); List<Integer> ans = new ArrayList<>(); Stack<TreeNode> stack = ne原创 2020-11-09 22:19:26 · 68 阅读 · 0 评论 -
回溯算法
1、含有相同元素求排列问题 public void dfs(List<List<Integer>> ans,List<Integer> list,int[] nums,boolean[] visit){ if(list.size()==nums.length) { ans.add(new ArrayList<Integer>(list));return ; } for(int i=0...原创 2020-10-27 09:56:29 · 80 阅读 · 0 评论 -
排序算法总结
1、快速排序 private void quickSort(int[] a, int begin, int end){ if(begin>end) return; int k = a[begin]; int i=begin; int j=end; while(i<j){ while(a[j]>=k&&i<j) j--; if(i<j) a[i++] = a[j]; ...原创 2020-09-29 10:40:20 · 75 阅读 · 0 评论