
数据结构
文章平均质量分 89
Yanliang_
The man who has made up his mind to win will never say "impossible ".
展开
-
堆排序
阅读原文堆排是基于堆的一种排序算法,对于堆的了解,请看什么是堆排序(如果对堆的插入和删除不清楚,强烈建议先看堆),今天我们聊聊堆排的思想,复杂度以及稳定性。堆排思想 前情回顾:克给谦子解决了时间管理上的问题:什么是堆排序过了几天后,谦子高兴地跑到老师跟前早知不来了,谦子心想谦子心想:上次去溪边游玩不是已经出过这个题吗,当时学会了冒泡排序,这次肯定不是那...原创 2018-01-02 22:43:28 · 268 阅读 · 0 评论 -
LeetCode – 198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent hous...原创 2019-02-11 11:34:55 · 187 阅读 · 0 评论 -
LeetCode – 759. Employee Free Time
We are given a list schedule of employees, which represents the working time for each employee.Each employee has a list of non-overlapping Intervals, and these intervals are in sorted order.Ret...原创 2019-02-11 11:35:50 · 540 阅读 · 0 评论 -
LeetCode – 583. Delete Operation for Two Strings
Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in eith...原创 2019-02-11 11:36:54 · 202 阅读 · 0 评论 -
LeetCode – 21. Merge Two Sorted List
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: ...原创 2019-02-12 09:26:39 · 222 阅读 · 0 评论 -
为什么大部分编程语言的数组的下标都从0开始?
众所周知,数组的一大优点是随机访问,如何实现随机访问呢?数组的特点:线性连续的内存空间和相同类型的数据基于以上两个特点也就决定了数组原生的支持随机访问的特性。数组是如何实现根据下标随机访问数组元素的呢?下面我们用一个长度为5的int类型的数组为例,来看一下它的具体实现 https://uploader.shimo.im/f/l1upJJqvVl8DdrnW.png如上图,数组为...原创 2019-02-12 09:30:23 · 961 阅读 · 0 评论 -
LeetCode – 547. Friend Circles
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a ...原创 2019-02-12 09:35:28 · 224 阅读 · 0 评论 -
阻塞队列 BlockingQueue
BlockingQueues在java.util.concurrent包下,提供了线程安全的队列访问方式,当阻塞队列插入数据时,如果队列已经满了,线程则会阻塞,等待队列中元素被取出后再插入,当从阻塞队列中取数据时,如果队列是空的,则线程会阻塞,等待队列中有新元素。BlockingQueue的核心方法package java.util.concurrent;import java....原创 2019-02-13 11:32:14 · 298 阅读 · 0 评论 -
LeetCode – 768. Max Chunks To Make Sorted II
This question is the same as "Max Chunks to Make Sorted" except the integers of the given array are not necessarily distinct, the input array could be up to length 2000, and the elements could b...原创 2019-02-14 15:21:19 · 526 阅读 · 0 评论 -
LeetCode – 740. Delete and Earn
Given an array nums of integers, you can perform operations on the array.In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must...原创 2019-02-11 11:32:40 · 332 阅读 · 0 评论 -
LeetCode – 802. Find Eventual Safe States
In a directed graph, we start at some node and every turn, walk along a directed edge of the graph. If we reach a node that is terminal (that is, it has no outgoing directed edges), we stop....原创 2019-02-11 11:31:08 · 265 阅读 · 0 评论 -
LeetCode – 739. Daily Temperatures
Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for...原创 2019-02-11 11:29:46 · 291 阅读 · 0 评论 -
常用排序算法总结
排序定义排序是计算机内经常进行的一种操作,其目的是将一组“无序”的记录序列调整为“有序”的记录序列。输入:n个数:a1,a2,a3,…,an 输出:n个数的排列:a1’,a2’,a3’,…,an’,使得a1’<=a2’<=a3’<=…<=an’。导致算法优劣的因素稳定:如果a原本在b前面,而a=b,排序之后a仍然在b的前面; 不稳定:如果a原...原创 2018-04-05 12:03:53 · 171 阅读 · 0 评论 -
快速排序及优化
快速排序原理快速排序是C.R.A.Hoare提出的一种交换排序。它采用分治的策略,所以也称其为分治排序。实现快速排序算法的关键在于,先在数组中选一个数作为基数,接着以基数为中心将数组中的数字分为两部分,比基数小的放在数组的左边,比基数大的放到数组的右边。接下来我们可以用递归的思想分别对基数的左右两边进行排序。整个快速排序可以总结为以下三步:从数组中取出一个数作为基数分区...原创 2018-05-21 20:05:14 · 299 阅读 · 0 评论 -
杀死进程-LeetCode-582
英文版582. Kill ProcessGiven n processes, each process has a unique PID (process id) and its PPID (parent process id).Each process only has one parent process, but may have one or more children proces...原创 2018-10-11 08:53:14 · 2744 阅读 · 0 评论 -
最长斐波那契序列-LeetCode-873
英文版A sequence X_1, X_2, …, X_n is fibonacci-like if:n >= 3X_i + X_{i+1} = X_{i+2} for all i + 2 <= nGiven a strictly increasing array A of positive integers forming a sequence, find the le...原创 2018-10-09 22:12:40 · 425 阅读 · 0 评论 -
LeetCode - 875. Koko Eating Bananas
Koko loves to eat bananas. There are N piles of bananas, the i-th pile has piles[i] bananas. The guards have gone and will come back in H hours.Koko can decide her bananas-per-hour eating speed ...原创 2019-02-11 11:23:21 · 287 阅读 · 0 评论 -
LeetCode – 801. Minimum Swaps To Make Sequences Increasing
We have two integer sequences A and B of the same non-zero length.We are allowed to swap elements A[i] and B[i]. Note that both elements are in the same in...原创 2019-02-11 11:25:52 · 213 阅读 · 0 评论 -
LeetCode – 752. Open the Lock
You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots:'0', '1', '2', '3', '4', '5', '6', '7', '8', '9' The wheels can rotate freely and wrap around: for example, we can turn...原创 2019-02-11 11:27:19 · 239 阅读 · 0 评论 -
LeetCode – 718. Maximum Length of Repeated Subarray
Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Explanation: The ...原创 2019-02-11 11:28:39 · 256 阅读 · 0 评论 -
LeetCode – 769. Max Chunks To Make Sorted
Given an array arr that is a permutation of [0, 1, ..., arr.length - 1], we split the array into some number of "chunks" (partitions), and individually sort each chunk. After con...原创 2019-02-14 15:24:25 · 504 阅读 · 0 评论