![](https://img-blog.csdnimg.cn/direct/f26fd0cefbe0483b8e865413579e44ca.jpeg?x-oss-process=image/resize,m_fixed,h_224,w_224)
LeetCode
文章平均质量分 67
1)Leetcode刷题记录
2)Leetcode分专题讲解
菜鸟Octopus
某生鲜领域供应链算法
展开
-
LeetCode:258.Add Digits (数字相加)
Given a non-negative integernum, repeatedly add all its digits until the result has only one digit.题目解析:所谓树根,就是将大于10的数的各个位上的数字相加,若结果还大于0的话,则继续相加,直到数字小于10为止。Example:Input: 38Output: 2 Explanati...原创 2020-02-05 21:46:44 · 302 阅读 · 0 评论 -
LeetCode: 240.Search2D(查找数字)
DescriptionWrite an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right. Int...原创 2020-02-04 00:06:45 · 301 阅读 · 1 评论 -
LeetCode: 67. Add Binary(二进制相加)
Given two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.题目描述:对二进制数进行相加Example 1:Input: a = "11", b = "1"Out...原创 2020-02-04 20:21:48 · 307 阅读 · 0 评论 -
LeetCode:122.Best Time Buy(最好时间购买股票)
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one ...原创 2020-02-06 16:48:52 · 221 阅读 · 0 评论 -
LeetCode:561. Array Partition(数组分割)
Given an array of2nintegers, your task is to group these integers intonpairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as poss...原创 2020-01-15 17:44:25 · 382 阅读 · 1 评论 -
LeetCode: 938. Range Sum of BST(二叉树在一个范围内求和)
Given therootnode of a binary search tree, return the sum of values of all nodes with value betweenLandR(inclusive).The binary search tree is guaranteed to have unique values.题目描述:二叉树范围内求和...原创 2020-01-16 11:30:51 · 283 阅读 · 1 评论 -
LeetCode: 733.Flood Fill(对二维数组进行转换)
Animageis represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).Given a coordinate(sr, sc)representing the starting pixel (row and colu...原创 2020-02-01 17:02:40 · 446 阅读 · 1 评论 -
LeetCode: 219.Contains Duplicate(包含重复的数)
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k....原创 2020-02-07 19:26:58 · 194 阅读 · 1 评论 -
LeetCode:1185.Day Of The Week(判断星期几)
Given a date, return the corresponding day of the week for that date.The input is given as three integers representing theday,monthandyearrespectively.Return the answer as one of the followin...原创 2020-02-08 23:45:21 · 473 阅读 · 1 评论 -
LeetCode:1154.Day Of Year(日期为一年中多少天)
Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.题目描述:日期为一年中第几天?Example 2:Input: date = “2019-02-10”Output: 41Example 3:...原创 2020-02-11 23:01:30 · 525 阅读 · 1 评论 -
LeetCode:145.Binary Tree Post Order Traversal(二叉树后序遍历)
文章最前: 我是Octopus,这个名字来源于我的中文名--章鱼;我热爱编程、热爱算法、热爱开源。所有源码在我的个人github;这博客是记录我学习的点点滴滴,如果您对 Python、Java、AI、算法有兴趣,可以关注我的动态,一起学习,共同进步。相关文章:LeetCode:55. Jump Game(跳远比赛) Leetcode:300. Longest Increasing Subsequence(最大增长序列) LeetCode:560. Subarray Sum Equals ...原创 2020-09-30 14:47:02 · 354 阅读 · 0 评论 -
LeetCode:快速排序
快速排序(Quicksort)是对冒泡排序的一种改进。 它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别进行快速排序,整个排序过程可以递归进行,以此达到整个数据变成有序序列。 设要排序的数组是A[0]……A[N-1],首先任意选取一个数据(通常选用数组的第一个数)作为关键数据,...原创 2018-08-20 17:41:54 · 3209 阅读 · 1 评论 -
LeetCode:657. Robot Return to Origin(机器人回到原点)
描述:There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robotends up at (0, 0)after it completes its moves.The move sequence is re...原创 2018-10-30 13:55:42 · 532 阅读 · 1 评论 -
LeetCode:728. Self Dividing Numbers(找出范围内自除数)
Aself-dividing numberis a number that is divisible by every digit it contains.For example, 128 is a self-dividing number because128 % 1 == 0,128 % 2 == 0, and128 % 8 == 0.Also, a self-dividin...原创 2020-01-15 09:56:12 · 244 阅读 · 1 评论 -
LeetCode:217. Contains Duplicate(数组中是否有重复的数)
Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element i...原创 2020-01-14 17:24:36 · 199 阅读 · 2 评论 -
LeetCode:709.Low First Char(开头字符串小写)
Description:Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.题目描述:将大写字母变成小写Example 1:Input: "Hello"Output: "hello"Example 2:Input: ...原创 2020-02-09 20:48:55 · 328 阅读 · 1 评论 -
LeetCode:925.Is Long Pressed(是不是长压字符串)
你检查键盘的键入字符。 如果可能是你的朋友姓名,则返回True,其中一些字符(可能没有)被长按。例如1:输入:name =“alex”,typed =“aaleex”输出:true说明:'alex'中的'a'和'e'被长按。例如2:输入:name =“laiden”,typed =“laiden”输出:true说明:没有必要长按任何字符。java实现方式1: ...原创 2020-02-10 13:48:06 · 168 阅读 · 1 评论 -
LeetCode: 1217.Play With Chips(玩筹码)
There are some chips, and the i-th chip is at position chips[i].You can perform any of the two following types of moves any number of times (possibly zero) on any chip:Move the i-th chip by 2 unit...原创 2020-02-12 17:41:45 · 356 阅读 · 1 评论 -
LeetCode: 14.Longest Common(最长公共起始串)
编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串""。示例 1:输入: ["flower","flow","flight"]输出: "fl"示例2:输入: ["dog","racecar","car"]输出: ""解释: 输入不存在公共前缀。说明:所有输入只包含小写字母a-z。java实现方式1:package...原创 2020-02-13 23:53:16 · 181 阅读 · 1 评论 -
LeetCode:94.Binary Tree Inorder Traversal(二叉树中序遍历)
文章最前: 我是Octopus,这个名字来源于我的中文名--章鱼;我热爱编程、热爱算法、热爱开源。所有源码在我的个人github;这博客是记录我学习的点点滴滴,如果您对 Python、Java、AI、算法有兴趣,可以关注我的动态,一起学习,共同进步。相关文章:LeetCode:55. Jump Game(跳远比赛) Leetcode:300. Longest Increasing Subsequence(最大增长序列) LeetCode:560. Subarray Sum Equals ...原创 2020-06-23 18:19:41 · 232 阅读 · 1 评论 -
LeetCode:96. Unique Binary Search Trees(找出独一无二搜索树)
文章最前: 我是Octopus,这个名字来源于我的中文名--章鱼;我热爱编程、热爱算法、热爱开源。所有源码在我的个人github;这博客是记录我学习的点点滴滴,如果您对 Python、Java、AI、算法有兴趣,可以关注我的动态,一起学习,共同进步。相关文章:LeetCode:55. Jump Game(跳远比赛) Leetcode:300. Longest Increasing Subsequence(最大增长序列) LeetCode:560. Subarray Sum Equals K..原创 2020-07-17 16:54:31 · 181 阅读 · 1 评论 -
LeetCode:1071.GreatestCommon(最大重复子串)
对于字符串S 和T,只有在 S = T + ... + T(T与自身连接 1 次或多次)时,我们才认定“T 能除尽 S”。返回字符串X,要求满足X 能除尽 str1 且X 能除尽 str2。示例 1:输入:str1 = "ABCABC", str2 = "ABC"输出:"ABC"示例 2:输入:str1 = "ABABAB", str2 = "ABAB"输...原创 2020-02-15 22:19:06 · 262 阅读 · 1 评论 -
如果设计和实现一个LFU(least frequently used )
1) 设计一个LFU2) 设计一个LRU原创 2020-04-08 12:01:03 · 284 阅读 · 1 评论 -
如果设计一个LRU(最少访问次数)
LRU 是 Least Recently Used 的简写,字面意思则是最近最少使用。通常用于缓存的淘汰策略实现,由于缓存的内存非常宝贵,所以需要根据某种规则来剔除数据保证内存不被撑满。原创 2020-04-08 18:18:37 · 339 阅读 · 1 评论 -
0-1 背包问题
对于一组不同重量,不可分割的物品,选择其中一些物品装入背包,能不能正好装满背包?状态:boolean dp[n][w+1] 记录每阶段可达状态原创 2023-01-01 14:40:26 · 125 阅读 · 0 评论 -
LeetCode:144.Binary Tree PreOrder Traversal(二叉树前序遍历)
文章最前: 我是Octopus,这个名字来源于我的中文名--章鱼;我热爱编程、热爱算法、热爱开源。所有源码在我的个人github;这博客是记录我学习的点点滴滴,如果您对 Python、Java、AI、算法有兴趣,可以关注我的动态,一起学习,共同进步。相关文章:LeetCode:55. Jump Game(跳远比赛) Leetcode:300. Longest Increasing Subsequence(最大增长序列) LeetCode:560. Subarray Sum Equals ...原创 2020-09-30 16:48:04 · 210 阅读 · 1 评论 -
LeetCode:57. Insert Interval (向一个区间中插入一个区间)
文章最前: 我是Octopus,这个名字来源于我的中文名--章鱼;我热爱编程、热爱算法、热爱开源。所有源码在我的个人github;这博客是记录我学习的点点滴滴,如果您对 Python、Java、AI、算法有兴趣,可以关注我的动态,一起学习,共同进步。相关文章:LeetCode:55. Jump Game(跳远比赛) Leetcode:300. Longest Increasing Subsequence(最大增长序列) LeetCode:560. Subarray Sum Equals K..原创 2021-01-19 15:50:26 · 381 阅读 · 1 评论 -
LeetCode:208. Implement Trie (实现Trie树)
文章最前: 我是Octopus,这个名字来源于我的中文名--章鱼;我热爱编程、热爱算法、热爱开源。所有源码在我的个人github;这博客是记录我学习的点点滴滴,如果您对 Python、Java、AI、算法有兴趣,可以关注我的动态,一起学习,共同进步。相关文章:LeetCode:55. Jump Game(跳远比赛) Leetcode:300. Longest Increasing Subsequence(最大增长序列) LeetCode:560. Subarray Sum Equals K..原创 2021-05-27 18:04:49 · 172 阅读 · 0 评论 -
完全-背包问题
有n个物品,重量分别为weight[i] (0-n-1),每个物品有无限多个,选择一些物品装入背包,在不超过背包重量w的前提下原创 2023-01-02 15:30:10 · 144 阅读 · 0 评论 -
Leetcode题目汇总
文章最前: 我是Octopus,这个名字来源于我的中文名--章鱼;我热爱编程、热爱算法、热爱开源。所有源码在我的个人github;这博客是记录我学习的点点滴滴,如果您对 Python、Java、AI、算法有兴趣,可以关注我的动态,一起学习,共同进步。1) Array题型733.Flood Fill(对二维数组进行转换) 240.Search2D(查找数字) 57. Insert Interval (向一个区间中插入一个区间) 42. Trapping Rain Water(能装多少水问题..原创 2021-09-29 16:08:27 · 169 阅读 · 0 评论 -
LeetCode:88. Merge Sorted Array(按照要求合并数组)
Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:The number of elements initialized innums1andnums2aremandnrespectively.You may assume that...原创 2019-10-24 14:34:22 · 121 阅读 · 0 评论 -
LeetCode:Joseph Problem(关于约瑟夫环问题)
问题描述:约瑟夫环(约瑟夫问题)是一个数学的应用问题:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围,从编号为k的人开始报数,数到m的那个人出列;他的下一个人又从1开始报数,数到m的那个人又出列;依此规律重复下去,直到圆桌周围的人只有一个没有出列。假设n=1000,k=5,m=13,问剩下最后一个人编号。java实现方式:package JosephProblem;...原创 2018-08-16 21:37:21 · 8377 阅读 · 7 评论 -
LeetCode 3. Longest Substring Without Repeating Characters(最长无重复字符串)
输出一个正整数:n,让括号进行正确匹配, 列出它的所有正确的排列方式:package PairsOfParentheses;import java.util.ArrayList;import java.util.List;import java.util.Scanner;import org.junit.Test;public class testPairOfP...原创 2018-08-20 11:41:28 · 269 阅读 · 1 评论 -
LeetCode:Sorted Question (排序顺序问题)
问题:手里面有1到n排序的纸牌,按照从上到下排列,现在对它进行如下操作:将第一张放到桌子上,再取一张放到纸牌堆底,这样循环操作,直到手里面没纸牌为止;那么假设桌子上的顺序是1到n,那么手上的牌原始排序是?package acm;import java.util.HashMap;import java.util.LinkedList;import java.util.List;imp...原创 2018-09-10 10:27:16 · 439 阅读 · 0 评论 -
LeetCode: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...原创 2018-10-12 10:30:31 · 367 阅读 · 2 评论 -
LeetCode:557. Reverse Words in a String III(反转每个单词)
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest"...原创 2018-10-12 11:27:30 · 187 阅读 · 0 评论 -
LeetCode:541.Reverse String II(按照要求反转字符串)
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them...原创 2018-10-14 17:01:52 · 249 阅读 · 0 评论 -
LeetCode:520.Detect Capital(检测大小写字母)
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in this ...原创 2018-10-15 15:51:53 · 162 阅读 · 0 评论 -
LeetCode:350,Intersection of Two Arrays II(数组的的相交)
Given two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2,2]Example 2:Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]Output: ...原创 2018-10-16 11:13:13 · 157 阅读 · 0 评论 -
LeetCode:349.Intersection of Two Arrays(求两个数组的交集且不重合)
Given two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]Example 2:Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]Output: [9...原创 2018-10-16 20:42:33 · 208 阅读 · 0 评论