![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
慢慢爬之轻算法
yanguo110
这个作者很懒,什么都没留下…
展开
-
50-Remove Covered Intervals
题目地址:Remove Covered Intervals。Given a list of intervals, remove all intervals that are covered by another interval in the list. Interval [a,b) is covered by interval [c,d) if and only if c <= a a...原创 2020-03-11 11:35:40 · 201 阅读 · 0 评论 -
49-Generate Random Point in a Circle
题目地址:Generate Random Point in a CircleGiven the radius and x-y positions of the center of a circle, write a function randPoint which generates a uniform random point in the circle.Note:input and o...原创 2020-03-05 16:12:08 · 169 阅读 · 0 评论 -
48-Longest Increasing Path in a Matrix
题目地址:Longest Increasing Path in a MatrixGiven an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You ...原创 2020-03-05 10:10:39 · 165 阅读 · 0 评论 -
47-Course Schedule II
题目地址:Course Schedule IIThere are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, whic...原创 2020-03-03 17:21:34 · 125 阅读 · 0 评论 -
46-Course Schedule
题目地址:Course ScheduleThere are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which i...原创 2020-03-02 18:26:54 · 104 阅读 · 0 评论 -
45-Binary Search Tree to Greater Sum Tree
题目地址:Binary Search Tree to Greater Sum TreeGiven the root of a binary search tree with distinct values, modify it so that every node has a new value equal to the sum of the values of the original tr...原创 2020-02-27 15:57:37 · 100 阅读 · 0 评论 -
44-Implement Rand10() Using Rand7()
题目地址:Implement Rand10() Using Rand7()Given a function rand7 which generates a uniform random integer in the range 1 to 7, write a function rand10 which generates a uniform random integer in the rang...原创 2020-02-25 18:18:20 · 66 阅读 · 0 评论 -
43-Linked List Random Node
题目地址:Linked List Random NodeGiven a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen.Follow up:What if the linked lis...原创 2020-02-25 13:47:28 · 167 阅读 · 0 评论 -
42- Subsets
题目地址:SubsetsGiven a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[[...原创 2020-01-04 15:59:36 · 93 阅读 · 0 评论 -
41- Combinations
题目地址:CombinationsGiven two integers n and k, return all possible combinations of k numbers out of 1 … n.Example:Input: n = 4, k = 2Output:[[2,4],[3,4],[2,3],[1,2],[1,3],[1,4],]class Sol...原创 2019-12-30 16:10:16 · 89 阅读 · 0 评论 -
40-Permutation Sequence
题目地址:Permutation SequenceThe set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence for n = 3:“123”“132...原创 2019-12-22 10:57:38 · 88 阅读 · 0 评论 -
三天一题-39-Sort Colors
题目地址:Sort ColorsGiven an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, w...原创 2019-12-14 17:26:49 · 91 阅读 · 0 评论 -
三天一题-38-Merge Intervals
题目地址:Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.D...原创 2019-12-04 10:40:50 · 93 阅读 · 0 评论 -
三天一题-37-Jump Game
题目地址:Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.D...原创 2019-11-27 21:49:48 · 82 阅读 · 0 评论 -
三天一题-36-Spiral Matrix
题目地址:Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Example 1:Input:[[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]Output: [1,2,3,...原创 2019-11-24 16:13:21 · 101 阅读 · 0 评论 -
三天一题-35-字母异位词分组
题目地址: 字母异位词分组给定一个字符串数组,将字母异位词组合在一起。字母异位词指字母相同,但排列不同的字符串。示例:输入: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],输出:[[“ate”,“eat”,“tea”],[“nat”,“tan”],[“bat”]]说明:所有输入均为小写字母。不考虑答案输出的顺序。来源:力扣(Lee...原创 2019-11-19 14:22:02 · 113 阅读 · 0 评论 -
三天一题-34- Rotate Image
题目地址: Rotate Image描述:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify...原创 2019-11-13 10:07:39 · 107 阅读 · 0 评论 -
三天一题-33-Combination SumII(回溯思想)
题目地址: Combination Sum II描述:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target....原创 2019-11-02 17:22:24 · 102 阅读 · 0 评论 -
三天一题-32-Combination Sum(回溯思想)
题目地址: Combination Sum描述:Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums ...原创 2019-10-28 10:02:40 · 113 阅读 · 0 评论 -
三天一题-31-Valid Sudoku
题目地址: Valid Sudoku描述:Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.E...原创 2019-10-21 10:24:30 · 95 阅读 · 0 评论 -
三天一题-30-Find First and Last Position of Element in Sorted Array
题目地址:Find First and Last Position of Element in Sorted Array描述:Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.Your algorith...原创 2019-10-17 14:02:06 · 98 阅读 · 0 评论 -
三天一题-29-Search in Rotated Sorted Array
题目地址:Search in Rotated Sorted Array描述:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are gi...原创 2019-10-14 15:19:17 · 107 阅读 · 0 评论 -
三天一题-20- Integer to Roman(Integer转成古罗马数字)
题目原地址:Integer to Roman描述:For example, two is written as II in Roman numeral, just two one’s added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written a...原创 2019-08-11 14:30:45 · 107 阅读 · 0 评论 -
三天一题-09-计数排序
借鉴:借鉴跳转,上面都有详细的描述以及动图的实现。计数排序计数排序(Counting Sort):它的优势在于在对一定范围内的整数排序时,它的复杂度为Ο(n+k)(其中k是整数的范围),快于任何比较排序算法。 [1-2] 当然这是一种牺牲空间换取时间的做法,而且当O(k)>O(nlog(n))的时候其效率反而不如基于比较的排序(基于比较的排序的时间复杂度在理论上的下限是O(nlo...原创 2019-07-03 23:35:28 · 144 阅读 · 0 评论 -
三天一题-28-Next Permutation
题目地址:Next Permutation描述:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange i...原创 2019-10-10 15:06:12 · 87 阅读 · 0 评论 -
三天一题-27-两数相除
题目地址:两数相除描述:给定两个整数,被除数 dividend 和除数 divisor。将两数相除,要求不使用乘法、除法和 mod 运算符。返回被除数 dividend 除以除数 divisor 得到的商。示例 1:输入: dividend = 10, divisor = 3输出: 3示例 2:输入: dividend = 7, divisor = -3输出: -2说明:被...原创 2019-09-24 14:20:56 · 130 阅读 · 0 评论 -
三天一题-15-Longest Substring Without Repeating Characters
题目地址:Longest Substring Without Repeating Characters描述:Given a string, find the length of the longest substring without repeating characters.(求去重后的字符串的长度)Example 1:Input: "abcabcbb" Output: 3 Ex...原创 2019-07-23 23:08:29 · 67 阅读 · 0 评论 -
三天一题-10-基数排序
借鉴:借鉴跳转,上面都有详细的描述以及动图的实现。基数排序计数排序(Radix Sort):基数排序(radix sort)属于“分配式排序”(distribution sort),又称“桶子法”(bucket sort)或bin sort,顾名思义,它是透过键值的部份资讯,将要排序的元素分配至某些“桶”中,藉以达到排序的作用,基数排序法是属于稳定性的排序,其时间复杂度为O (nlog®...原创 2019-07-07 00:46:04 · 181 阅读 · 0 评论 -
三天一题-12-二分法查找
借鉴:java源码-Arrays.binarySearch二分法查找 (Binary Search) 二分法查找适用于数据量较大时,但是数据需要先排好顺序。主要思想是:(设查找的数组区间为array[low, high])。1)确定该区间的中间位置K。2)将查找的值T与array[k]比较。若相等,查找成功返回此位置;否则确定新的查找区域,继续二分查找。区域确定如下:a.arr...原创 2019-07-13 23:12:22 · 138 阅读 · 0 评论 -
三天一题-11-桶排序
借鉴:借鉴跳转,上面都有详细的描述以及动图的实现。桶排序(Bucket Sort)桶排序 (Bucket sort)或所谓的箱排序,是一个排序算法,工作的原理是将数组分到有限数量的桶子里。每个桶子再个别排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排序)。–百度百科import java.util.ArrayList;import java.util.LinkedL...原创 2019-07-09 23:55:41 · 117 阅读 · 0 评论 -
三天一题-07-快速排序
借鉴:借鉴跳转,上面都有详细的描述以及动图的实现。快速排序快速排序(Quick Sort):通过一趟排序将待排记录分隔成独立的两部分,其中一部分记录的关键字均比另一部分的关键字小,则可分别对这两部分记录继续进行排序,以达到整个序列有序。public class QuickSortDemo { private static int partition(int[] arr, in...原创 2019-06-28 23:57:01 · 145 阅读 · 0 评论 -
三天一题-08-归并排序
借鉴:借鉴跳转,上面都有详细的描述以及动图的实现。归并排序归并排序(Merge Sort):把长度为n的输入序列分成两个长度为n/2的子序列;对这两个子序列分别采用归并排序;将两个排序好的子序列合并成一个最终的排序序列。public class MergeSort { private static int[] arr; public static void main...原创 2019-07-01 22:59:10 · 93 阅读 · 0 评论 -
三天一题-05-希尔排序
借鉴:借鉴跳转,上面都有详细的描述以及动图的实现。希尔排序/** * 简单排序-希尔排序 * 从小到大排序 */public class ShellSort { private static int[] shellSort(int[] arr) { int length = arr.length; int temp, len = lengt...原创 2019-06-23 00:49:38 · 151 阅读 · 0 评论 -
三天一题-06-堆排序
借鉴:借鉴跳转,上面都有详细的描述以及动图的实现。堆排序堆排序(Heapsort)是指利用堆这种数据结构所设计的一种排序算法。堆积是一个近似完全二叉树的结构,并同时满足堆积的性质:即子结点的键值或索引总是小于(或者大于)它的父节点。...原创 2019-06-25 23:27:19 · 100 阅读 · 0 评论 -
三天一题-01-子字符串查找
给定一段长度为N的文本和一个长度为M的模式的字符串,在文本中找到与该模式相符的字符串。暴力解法public static int serch(String pattern,String source){ int pl = pattern.length(); int sl = source.length(); for(int i = 0;i <= sl-pl ; i++){...原创 2019-06-10 17:37:28 · 186 阅读 · 0 评论 -
三天一题-04-冒泡排序
冒泡排序借鉴:借鉴跳转,上面都有详细的描述以及动图的实现。//冒泡排序public class BubbleSort { // 从小到大排序 public static int[] bubbleSort(int[] arr){ int temp ; int length = arr.length; for (int i = ...原创 2019-06-20 00:03:37 · 122 阅读 · 0 评论 -
三天一题-13-Median of Two Sorted Arrays
借鉴来自:Cheng_Zhang的discussThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n))....原创 2019-07-16 23:57:00 · 88 阅读 · 0 评论 -
三天一题-14-Add Two Numbers
题目地址:[leetcode-Median of Two Sorted Arrays]原创 2019-07-21 00:37:25 · 104 阅读 · 0 评论 -
三天一题-26-两两交换链表中的节点
题目地址:Swap Nodes in Pairs描述:Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list’s nodes, only nodes itself may be changed.Example:Give...原创 2019-09-21 09:35:16 · 79 阅读 · 0 评论 -
三天一题-25-Generate Parentheses
题目地址:Generate Parentheses描述:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[“((()))”,“(()())”...原创 2019-09-15 21:44:35 · 91 阅读 · 0 评论