![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 60
tbabm_
一只进击中的程序员
展开
-
排序算法总结
排序算法总结总结总结稳定排序:相同值元素排序之后前后相对顺序不变1、不稳定排序:选择排序,希尔排序,快速排序,堆排序 快选希堆2、稳定排序:插入排序,冒泡排序,归并排序,计数排序 插冒归计原地排序:直接在原数组上进行,不申请额外数组空间非原地排序:归并排序十大排序算法1、选插冒 O(n*n)(1) 选择排序:(有序区,无序区); 在无序区中选择最小元素与无序区首元素交换; 无序区最小元素归位; 不稳定、原地排序(2) 冒泡排序原创 2021-09-01 10:25:13 · 197 阅读 · 0 评论 -
最大化最小值/ 最小化最大值问题
最大化最小值/ 最小化最大值问题基本题型: 给定n个整数序列,将其划分为m个连续子序列,求这m个子序列的和的最大化最小值 或者最小化最大值问题。解题思路: 二分法具体过程:根据题意,确定二分的上界与下界(一般为子序列和的可能取值、元素差值等)(有利于加快速度)确定二分中的分块条件,根据该条件与当前界限,对数组进行分块根据当前二分的块数调整上下界// leetcode 410. 分割数组的最大值// 题意:将数组分成m个非空连续子数组,使得这m个子数组各自和的最大值最小 ==== 最小化原创 2020-09-25 19:40:39 · 2647 阅读 · 1 评论 -
回溯+剪枝+去重 LeetCode : 39组合总和;LeetCode 40组合总和II; LeetCode 46 全排列;LeetCode 47全排列 II
数组取元素搞排列:递归、回溯、剪枝想象一棵树,树中不同层次、不同节点即代表了当前选择的不同状态。dfs遍历该树,根据题目条件进行剪枝回溯,找出所有满足结果即可。取全部元素:使用标记数组,每次都需要判断每个元素是否可用;取部分元素:可按照顺序(数组下标)取满足条件的一部分数据,判断是否可用;数组相关解集无重复问题:一般需要首先对数组进行排序,遍历数组时考虑nums[i]=nums[i+1]这样某一区间元素相等的情况,大多都只需要对第一个或最后一个元素进行处理,而其他的跳过。结果集无重复:想原创 2020-08-16 11:37:22 · 173 阅读 · 0 评论 -
394. Decode String
Given an encoded string, return it's decoded string.The encoding rule is:k[encoded_string], where theencoded_stringinside the square brackets is being repeated exactlyktimes. Note thatkis gua...原创 2019-04-18 09:32:36 · 95 阅读 · 0 评论 -
389. Find the Difference
Given two stringssandtwhich consist of only lowercase letters.Stringtis generated by random shuffling stringsand then add one more letter at a random position.Find the letter that was adde...原创 2019-04-17 23:35:55 · 116 阅读 · 0 评论 -
136. Single Number
Given anon-emptyarray of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without us...原创 2019-04-17 23:21:23 · 81 阅读 · 0 评论 -
1025. Divisor Game
Alice and Bob take turns playing a game, with Alice starting first.Initially, there is a numberNon the chalkboard. On each player's turn, that player makes amoveconsisting of:Choosinganyxw...原创 2019-04-17 23:07:18 · 151 阅读 · 0 评论 -
1002. Find Common Characters
Given an arrayAof strings made only from lowercase letters, return a list of all characters that show up in all strings within the list(including duplicates).For example, if a character occurs 3 ...原创 2019-04-17 22:56:47 · 167 阅读 · 0 评论 -
771. Jewels and Stones
You're given stringsJrepresenting the types of stones that are jewels, andSrepresenting the stones you have. Each character inSis a type of stone you have. You want to know how many of the sto...原创 2019-04-17 22:41:37 · 73 阅读 · 0 评论 -
690. Employee Importance
You are given a data structure of employee information, which includes the employee'sunique id, hisimportance valueand hisdirectsubordinates' id.For example, employee 1 is the leader of employe...原创 2019-04-22 19:02:25 · 95 阅读 · 0 评论 -
1. Two Sum
Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use thesame...原创 2019-04-22 18:43:34 · 77 阅读 · 0 评论 -
811. Subdomain Visit Count
A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcode.com"...原创 2019-04-22 16:59:53 · 341 阅读 · 0 评论 -
748. Shortest Completing Word
Find the minimum length word from a given dictionarywords, which has all the letters from the stringlicensePlate. Such a word is said tocompletethe given stringlicensePlateHere, for letters we ...原创 2019-04-22 23:16:10 · 119 阅读 · 0 评论 -
347. Top K Frequent Elements
Given a non-empty array of integers, return thekmost frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]Note:You...原创 2019-04-23 00:03:19 · 84 阅读 · 0 评论 -
976. Largest Perimeter Triangle
Given an arrayAof positive lengths, return the largest perimeter of a triangle withnon-zero area, formed from 3 of these lengths.If it is impossible to form anytriangle of non-zero area, return...原创 2019-05-17 12:34:59 · 92 阅读 · 0 评论 -
949. Largest Time for Given Digits
Given an array of 4 digits, return the largest 24 hour time that can be made.The smallest 24 hour time is 00:00, and the largest is 23:59. Starting from 00:00, a time is larger if more time has ela...原创 2019-05-17 11:38:31 · 117 阅读 · 0 评论 -
1010. Pairs of Songs With Total Durations Divisible by 60
In a list of songs, thei-thsong has a duration oftime[i]seconds.Return the number of pairs of songs for which their totalduration in seconds is divisible by60. Formally, we want the number o...原创 2019-05-15 22:02:51 · 124 阅读 · 0 评论 -
1033. Moving Stones Until Consecutive
Three stones are on a number line at positionsa,b, andc.Each turn, you pick up a stone at an endpoint (ie., either the lowest or highest position stone), and move it to an unoccupied position bet...原创 2019-05-13 23:51:55 · 160 阅读 · 0 评论 -
973. K Closest Points to Origin
We have a list ofpointson the plane. Find theKclosest points to the origin(0, 0).(Here, the distance between two points on a plane is the Euclidean distance.)You may return the answer in any...原创 2019-04-23 16:07:48 · 163 阅读 · 0 评论 -
341. Flatten Nested List Iterator
Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list -- whose elements may also be integers or other lists.Example 1:Input: [[1,1],2...原创 2019-04-23 16:06:58 · 83 阅读 · 0 评论 -
451. Sort Characters By Frequency
Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:"tree"Output:"eert"Explanation:'e' appears twice while 'r' and 't' both appear once.So 'e'...原创 2019-04-18 13:25:09 · 112 阅读 · 0 评论 -
856. Score of Parentheses
Given a balanced parentheses stringS, compute the score of the string based on the following rule:()has score 1 ABhas scoreA + B, where A and B are balanced parentheses strings. (A)has score...原创 2019-04-18 12:56:40 · 142 阅读 · 0 评论 -
378. Kth Smallest Element in a Sorted Matrix
Given anxnmatrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not t...原创 2019-04-22 16:22:03 · 125 阅读 · 0 评论 -
173. Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next smallest number in the BST.Example:...原创 2019-04-09 23:10:26 · 74 阅读 · 0 评论 -
739. Daily Temperatures
Given a list of daily temperaturesT, 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 which...原创 2019-03-27 18:56:12 · 193 阅读 · 0 评论 -
94. Binary Tree Inorder Traversal
Given a binary tree, return theinordertraversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]Follow up:Recursive solution is trivial, could y...原创 2019-03-27 18:28:05 · 114 阅读 · 0 评论 -
20. Valid Parentheses
Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of b...原创 2019-03-27 18:18:22 · 80 阅读 · 0 评论 -
155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Ge...原创 2019-03-27 18:16:02 · 84 阅读 · 0 评论 -
242. Valid Anagram
Given two stringssandt, write a function to determine iftis an anagram ofs.Example 1:Input: s = "anagram", t = "nagaram"Output: trueExample 2:Input: s = "rat", t = "car"Output: fal...原创 2019-03-27 18:00:40 · 124 阅读 · 0 评论 -
933. Number of Recent Calls
Write a classRecentCounterto count recent requests.It has only one method:ping(int t), where t represents some time in milliseconds.Return the number ofpings that have been made from 3000 mill...原创 2019-03-27 17:53:49 · 113 阅读 · 0 评论 -
225. Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. empty() -- Return ...原创 2019-03-27 17:26:51 · 157 阅读 · 0 评论 -
232. Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front element. em...原创 2019-03-27 16:56:18 · 140 阅读 · 0 评论 -
496. Next Greater Element I
You are given two arrays(without duplicates)nums1andnums2wherenums1’s elements are subset ofnums2. Find all the next greater numbers fornums1's elements in the corresponding places ofnums2....原创 2019-03-27 16:34:21 · 138 阅读 · 0 评论 -
503. Next Greater Element II
Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first gre...原创 2019-03-27 15:44:19 · 98 阅读 · 0 评论 -
706. Design HashMap
Design a HashMapwithout using any built-in hash table libraries.To be specific, your design should include these functions:put(key, value):Insert a (key, value) pair into the HashMap. If the va...原创 2019-04-02 10:07:50 · 83 阅读 · 0 评论 -
682. Baseball Game
You're now a baseball game point recorder.Given a list of strings, each string can be one of the 4 following types:Integer(one round's score): Directly represents the number of points you get in ...原创 2019-04-02 10:20:43 · 76 阅读 · 0 评论 -
844. Backspace String Compare
Given twostringsSandT,return if they are equal when both are typed into empty text editors.#means a backspace character.Example 1:Input: S = "ab#c", T = "ad#c"Output: trueExplanation: Bo...原创 2019-04-09 19:45:35 · 117 阅读 · 0 评论 -
961. N-Repeated Element in Size 2N Array
In a arrayAof size2N, there areN+1unique elements, and exactly one of these elements is repeated N times.Return the element repeatedNtimes.Example 1:Input: [1,2,3,3]Output: 3Examp...原创 2019-04-09 19:13:01 · 96 阅读 · 0 评论 -
1021. Remove Outermost Parentheses
A valid parentheses string is either empty(""),"(" + A + ")", orA + B, whereAandBare valid parentheses strings, and+represents string concatenation. For example,"","()","(())()", and"(()...原创 2019-04-09 18:47:19 · 579 阅读 · 0 评论 -
846. Hand of Straights
Alice has ahandof cards, given as an array of integers.Now she wants to rearrange the cards into groups so that each group is sizeW, and consists ofWconsecutive cards.Returntrueif and only ...原创 2019-03-29 09:26:50 · 173 阅读 · 0 评论