自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(164)
  • 收藏
  • 关注

原创 一看就懂的贪心算法

如何理解贪心算法我们先看一个例子假设有一个可以容纳100kg物品的背包,背包可以装各种物品,我们有以下五种豆子,每种豆子的重量和总价值各不相同。为了让背包中所装物品的总价值最大,我们如何选择在背包中装哪些豆子?每种豆子又应该装多少?我们可以这样想,我们只需要计算出每种豆子的单价,按照价格由高到低依次来装豆子,先按单价最高的豆子装,装不满的话,再装价格相对较低的豆子,直到装满为止。这个问题的解决思路就是用了贪心算法的思想,我们先来看以下贪心算法解决问题的步骤:第一步:套用贪心算法的问题

2021-10-23 15:26:47 32149 19

原创 栈的简单应用

栈的应用

2022-07-07 19:31:50 277 1

原创 双链表,循环链表,静态链表

简单链表的操作实线

2022-07-05 21:16:21 502

原创 单链表的简单使用

单链表的简单操作

2022-07-05 19:59:30 321

原创 顺序表的简单操作

线性表之顺序表的简单操作

2022-07-04 19:45:04 136

原创 《中英双解》leetcode H-Index(H指数)

给你一个整数数组 citations ,其中 citations[i] 表示研究者的第 i 篇论文被引用的次数。计算并返回该研究者的 h指数。根据维基百科上h 指数的定义:h 代表“高引用次数”,一名科研人员的 h指数是指他(她)的 (n 篇论文中)总共有 h 篇论文分别被引用了至少 h 次。且其余的 n - h篇论文每篇被引用次数不超过 h 次。如果 h 有多种可能的值,h 指数 是其中最大的那个。示例 1:输入:citations = [3,0,6,1,5]输出:3解...

2022-02-28 21:06:13 254

原创 《中英双解》leetcode Largest Perimeter Triangle(三角形的最大周长)

给定由一些正数(代表长度)组成的数组 nums,返回 由其中三个长度组成的、面积不为零的三角形的最大周长。如果不能形成任何面积不为零的三角形,返回0。Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a...

2022-02-25 21:55:16 83

原创 《中英双解》leetcode Sort Array By Parity(按奇偶排序数组)

给定一个非负整数数组 A,返回一个数组,在该数组中,A 的所有偶数元素之后跟着所有奇数元素。你可以返回满足此条件的任何数组作为答案。Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers.Return any array that satisfies this condition.来源:力扣(LeetCode..

2022-02-23 22:30:35 99

原创 《中英双解》leetcode Sort List

给你链表的头结点head,请将其按 升序 排列并返回 排序后的链表 。Given the head of a linked list, return the list after sorting it in ascending order.来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/sort-list著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。示例 1:输入:head = [4,2,1,3]输出:...

2022-02-22 21:43:51 237

原创 《中英双解》leetcode group Anagrams(字母异位词)

给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。Given an array of strings strs, group the anagrams together. You can return the answer in any order.An Anagram is a word or phrase formed by rearranging the letters.

2022-02-21 20:40:00 143

原创 《中英双解》leetcode 4Sum

Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:0 <= a, b, c, d< na, b, c, and d are distinct.nums[a] + nums[b] + nums[c] + nums[d] == targetYou may return the ans..

2022-02-20 20:56:38 110

原创 《中英双解》leetcode three Sum

16. 最接近的三数之和难度中等1045收藏分享切换为英文接收动态反馈给你一个长度为n的整数数组nums和 一个目标值target。请你从nums中选出三个整数,使它们的和与target最接近。返回这三个数的和。假定每组输入只存在恰好一个解。Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is clo...

2022-02-19 21:16:31 246

原创 《中英双解》leetcode Fair Candy Swap(公平糖果的交换)

爱丽丝和鲍勃拥有不同总数量的糖果。给你两个数组 aliceSizes 和 bobSizes ,aliceSizes[i] 是爱丽丝拥有的第 i 盒糖果中的糖果数量,bobSizes[j] 是鲍勃拥有的第 j 盒糖果中的糖果数量。两人想要互相交换一盒糖果,这样在交换之后,他们就可以拥有相同总数量的糖果。一个人拥有的糖果总数量是他们每盒糖果数量的总和。返回一个整数数组 answer,其中 answer[0] 是爱丽丝必须交换的糖果盒中的糖果的数目,answer[1] 是鲍勃必须交换的糖果盒中的糖果的数.

2022-02-18 20:16:39 130

原创 《中英双解》leetcode Largest Number A tLeast Twice Of Others

给你一个整数数组 nums ,其中总是存在 唯一的 一个最大整数 。请你找出数组中的最大元素并检查它是否 至少是数组中每个其他数字的两倍 。如果是,则返回 最大元素的下标 ,否则返回 -1 。示例 1:输入:nums = [3,6,1,0]输出:1解释:6 是最大的整数,对于数组中的其他整数,6 至少是数组中其他元素的两倍。6 的下标是 1 ,所以返回 1 。示例 2:输入:nums = [1,2,3,4]输出:-1解释:4 没有超过 3 的两倍大,所以返回 -1 。示例 .

2022-02-17 23:26:24 113

原创 《中英双解》leetcode Longest WordIn Dictionary

Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.If there is more than one possible answer, return the longest word with the smallest l.

2022-02-16 23:25:37 119

原创 《中英双解》leetcode Set Mismatch

集合 s 包含从 1 到n的整数。不幸的是,因为数据错误,导致集合里面某一个数字复制了成了集合里面的另外一个数字的值,导致集合 丢失了一个数字 并且 有一个数字重复 。给定一个数组 nums 代表了集合 S 发生错误后的结果。请你找出重复出现的整数,再找到丢失的整数,将它们以数组的形式返回。You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, d...

2022-02-15 23:28:37 85

原创 《中英双解》leetcode Maximum Product of Three Numbers(三个数的最大乘积)

给你一个整型数组 nums ,在数组中找出由三个数组成的最大乘积,并输出这个乘积。Given an integer array nums, find three numbers whose product is maximum and return the maximum product.来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/maximum-product-of-three-numbers著作权归领扣网络所有。商业转载请联系官方授.

2022-02-14 22:40:42 352

原创 《中英双解》leetcode Longest Harmonious Subsequence(最长和谐子序列)

We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.Given an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences.A subse.

2022-02-13 21:21:41 81

原创 比较器,堆结构,堆排序

比较器:1)比较器的实质就是重载比较运算符2)比较器可以很好的应用在特殊标准的排序上3)比较器可以很好的应用在根据特殊标准排序的结构上4)写代码变得异常容易,还用于泛型编程比较器的统一约定@Overridepublic int compare(T o1,T o2){ //返回负数的时候,就是o1比o2优先的情况 //返回正数的时候,就是o2比o1优先的情况 //返回0的情况,就是o1和o2同样优先的情况}public static class Stud

2022-02-05 16:25:09 376

原创 荷兰国旗问题和快速排序

荷兰国旗问题有两种情况: 1)给定一个数x,<= x的整体放在左边,>x的整体放在右边 2)给定一个数x,< x的整体放在左边,= x的整体放在中间,> x的整体放在右边 规定不需要辅助数组,时间复杂度O(N)完成上面的调整 现在先来看第一个情况:如图所示,我们先划分一个<=区域在左侧,第一个元素的下标位置是i,给定的数为x。现在我们需要对这个数组进行划分1.当i在3这个位置的时候,i位置和&l.

2022-01-26 12:13:43 662

原创 归并排序和一些例题

归并排序的原理并不是很复杂,他的意思是说,将一个数组从中间分解成左右两个部分,然后对左右两部分分别排序,将排序后的结果再进行合并。我们先来讨论经典的递归实现方法。归并排序的递归实现可以总结为:左边排好序+右边排好序+merge让总体有序这个问题最大的困难就是如何进行合并merge,我们通过画递归树可以知道,最后一定是一个元素和一个元素进行的merge,那么这个merge的过程还需要涉及到对这两个元素进行比较,那么如何去实现呢?这里我们采用双指针法和辅助数组的方式,首先创建一个辅助数组,左右两

2022-01-24 12:23:34 1636

原创 链表结构,栈,队列,递归行为,哈希表和有序表

链表的结构与数组有着很大的不同,他不像数组一样,需要一块连续的地址空间,他可以通过指针将零散的空间连接起来,更加有效的提高了空间的利用率。单链表:线性表的链式存储就叫做单链表,下面来看看如何进行定义:public class LinkedList{ public class Node{ public int data;//数据域 public Node next;//存储下一个节点的地址 } private Node head =

2022-01-23 11:36:05 405

原创 《中英双解》Intersection of Two Linked Lists(相交链表)

Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.For example, the following two linked lists begin to intersect at node c1:T.

2022-01-22 17:00:38 115

原创 异或运算和几个经典题目解析

认识异或运算异或运算就记成无进位相加0 1 11 0 11 1 0异或运算满足交换律和结合律同样一批数,不管选择什么样的顺序做异或运算,最后结果一定是一个如何不使用额外的变量交换两个数1)a = a ^ b2) b = a ^ b3) a = a ^ b比如说a = 甲,b = 乙1)a = 甲 ^ 乙,b = 乙2)b = 甲^乙^乙,a = 甲 ^ 乙3)a = 甲^乙^甲,b = 甲public static void swap(int[]

2022-01-21 10:44:18 1688

原创 认识复杂度,对数器,二分法

常见的常数时间操作常见的常数时间操作通常包括三种情况,第一固定的时间操作,第二寻址操作,第三就是非固定的时间操作。关于固定的时间操作我们可以这么理解int a = 1;int b = 2;上面这两行代码虽然是两行,但是他的时间复杂度确是O(1),假设我们把每一行执行的代码时间记作unit_time,那么执行这两行所需要的代码就是2unit_time,根据大O阶的表示方法既O(2)就可以表示位O(1).关于寻址操作我们大家都第一时间想到的可能就是数组的,数组支持随机访问,并且在O(1)的

2022-01-20 16:48:47 481

原创 《中英双解》leetcode Array Partition I(数组拆分)

Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.给定长度为2n的整数数组 nums ,你的任务是将这些数分成n 对, 例如 (a1, b1), (a2, b2)...

2022-01-17 23:02:16 221

原创 《中英双解》leetcode Relative Ranks(相对名次)

506. Relative Ranks难度简单170收藏分享切换为中文接收动态反馈You are given an integer arrayscoreof sizen, wherescore[i]is the score of theithathlete in a competition. All the scores are guaranteed to beunique.The athletes areplacedbased on their scores, where...

2022-01-14 22:32:02 136

原创 《中英双解》leetcode Third Maximum Number(第三大的数)

414. Third Maximum Number难度简单330收藏分享切换为中文接收动态反馈Given an integer arraynums, returnthethird distinct maximumnumber in this array. If the third maximum does not exist, return themaximumnumber.Example 1:Input: nums = [3,2,1]Output: 1Explana...

2022-01-13 17:49:59 112

原创 《中英双解》leetCode Intersection of Two Arrays(两个数组的交集)

349. Intersection of Two Arrays难度简单468收藏分享切换为中文接收动态反馈Given two integer arraysnums1andnums2, returnan array of their intersection. Each element in the result must beuniqueand you may return the result inany order.Example 1:Input: nums1 = ...

2022-01-12 12:32:18 183

原创 《中英双解》leetCode Peak Index in a Mountain Array 山脉数组的峰顶索引

852. Peak Index in a Mountain Array难度简单223收藏分享切换为中文接收动态反馈Let's call an arrayarramountainif the following properties hold:arr.length >= 3 There exists someiwith0 < i< arr.length - 1such that: arr[0] < arr[1] < ... arr[i-1] &...

2021-12-08 21:57:52 82

原创 《中英双解》leetCoded Find Smallest Letter Greater Than Target 寻找比目标字母大的最小字母

744.Find Smallest Letter Greater Than TargetEasy11281088Add to ListShareGiven a characters arraylettersthat is sorted innon-decreasingorder and a charactertarget, returnthe smallest character in the array that is larger thantarget.Notetha...

2021-12-07 21:56:05 63

原创 《中英双解》leetCode Arranging Coins (排列硬币)

Arranging Coins难度简单182收藏分享切换为中文接收动态反馈You havencoins and you want to build a staircase with these coins. The staircase consists ofkrows where theithrow has exactlyicoins. The last row of the staircasemay beincomplete.Given the integern, re...

2021-12-06 21:52:11 2983

原创 《中英双解》leetCode Find Peak Element(寻找峰值的元素)

162. Find Peak Element难度中等662收藏分享切换为中文接收动态反馈A peak element is an element that is strictly greater than its neighbors.Given an integer arraynums, find a peak element, and return its index. Ifthe array contains multiple peaks, return the index toan...

2021-12-04 21:17:17 349

原创 《中英双解》leetCode Number of province

547. Number of Provinces难度中等669收藏分享切换为中文接收动态反馈There arencities. Some of them are connected, while some are not. If cityais connected directly with cityb, and citybis connected directly with cityc, then cityais connected indirectly with city...

2021-12-03 20:06:11 89

原创 《中英双解》leetcode Merge Intervals(合并区间)

56.Merge IntervalsMedium10516454Add to ListShareGiven an arrayofintervalswhereintervals[i] = [starti, endi], merge all overlapping intervals, and returnan array of the non-overlapping intervals that cover all the intervals in the input.Exa...

2021-12-01 20:25:26 118

原创 《中英双解》leetCode Find the Middle Index in Array

Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones).A middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + num.

2021-11-30 20:46:00 81

原创 《中英双解》Roman to Integer(罗马数字转换)

13. Roman to IntegerRoman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D 500M 1000For exa...

2021-11-29 17:11:03 3088

原创 《中英双解》leetCode Find if path exists in graph

There is abi-directionalgraph withnvertices, where each vertex is labeled from0ton - 1(inclusive). The edges in the graph are represented as a 2D integer arrayedges, where eachedges[i] = [ui, vi]denotes a bi-directional edge between vertexuia...

2021-11-28 18:26:47 350

原创 《中英双解》leetCode Find Center of start Graph(找到星型图的中心节点)

There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.You are given a 2D integer array edges where e.

2021-11-27 16:01:20 3519

原创 《中英双解》leetCode Find the town judge(找到小镇法官)

In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.If the town judge exists, then:The town judge trusts nobody.Everybody (except for the town judge) trusts the town judge.There is .

2021-11-26 09:51:46 195

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除