
数据结构与算法
boker_han
这个作者很懒,什么都没留下…
展开
-
常见排序算法分析与实现(Java版)
1. 冒泡排序 核心提炼:相邻元素,两两比较并交换,逐趟进行,给人以水泡逐渐上浮的感觉 实现代码: /** * 冒泡排序(两两比较--交换) * @param arr */ public static void bubbleSort(int[] arr){ if(arr == null || arr.length ...原创 2018-09-10 21:37:21 · 230 阅读 · 0 评论 -
LeetCode训练营之排序
一、merge-sorted-array Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space to hold additional elements from B. The number of element...原创 2018-11-12 19:34:45 · 374 阅读 · 0 评论 -
数据结构与算法之二叉堆训练营
前言: 二叉堆本质上就是一个特殊的完全二叉树。其中,“特殊”表现在节点元素之间存在着大小规律,完全二叉树表示二叉堆的存储结构采用数组实现,只要记住这两点,二叉堆就不难理解和实现;二叉堆根据大小规律的不同,可以分为大顶堆和小顶堆。 概念简述: 二叉堆是一种完全二叉树,在这棵树中,任意父节点的值全部大于等于(小于等于)其子节点的值;其中如果任意父节点的值大于等于子节点的值,则该二叉堆就是大顶堆;如果任...原创 2018-11-08 10:07:12 · 332 阅读 · 0 评论 -
数据结构与算法之二叉树训练营
public ArrayList PrintFromTopToBottom(TreeNode root) { //返回的层序遍历结果 ArrayList result = new ArrayList<>(); if(root == null) return result; //根据层序遍历的特点符合队列的先进先出,使用队列作为中间容器,存放每一层的元素 Queue queue = ne..原创 2018-11-05 19:49:11 · 258 阅读 · 0 评论 -
数据结构与算法之队列与栈训练营
1.用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 public class QueueImplementedByStack { Stack<Integer> stack1 = new Stack<Integer>(); Stack<Integer> stack2 = new Stack<Inte...原创 2018-11-07 21:52:22 · 199 阅读 · 0 评论 -
数据结构与算法之链表训练营
1. 1 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList.(栈) public ArrayList&lt;Integer&gt; printListFromTailToHead(ListNode node) { //返回结果 ArrayList&lt;Integer&gt; result = new ArrayList&lt;&gt;(); ...原创 2018-11-07 19:53:35 · 234 阅读 · 0 评论 -
LeetCode训练营之链表
一、 add-two-numbers You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and ...原创 2018-11-10 18:36:13 · 403 阅读 · 0 评论 -
LeetCode训练营之二叉树
binary-tree-postorder-traversal Given a binary tree, return the preorder traversal of its nodes’ values. 方法一:递归实现前序遍历 方法二:迭代实现前序遍历(栈) public ArrayList&lt;Integer&gt; preorderTraversal(TreeNode roo...原创 2018-11-09 17:13:09 · 245 阅读 · 0 评论 -
LeetCode训练营之栈与队列
Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. public int largestRectangleArea(int[] he...原创 2018-11-09 13:48:29 · 259 阅读 · 0 评论 -
LeetCode训练营之字符串
longest-palindromic-substring(最长回文子串) Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromi...原创 2018-11-26 09:07:02 · 411 阅读 · 0 评论