
leetcode
文章平均质量分 72
与你一起学算法
一个不羁的码农,我的世界不只有coding,欢迎关注我的公众号「与你一起学算法」
展开
-
Python3、Java 实战LeetCode高频面试之单链表反转
单链表反转单链表反转这道题可谓是链表里面的高频问题了,差不多可以说只要被问到链表,就会问单链表反转。 今天我们就一起来看下。题目链接:https://leetcode-cn.com/problems/reverse-linked-list/题目描述:反转一个单链表。示例:输入: 1->2->3->4->5->NULL输出: 5->4->3->2->1->NULL解题思路这道题是非常经典的一道题了,没有很多的套路,主要方法有迭代法和原创 2021-03-07 17:25:43 · 240 阅读 · 0 评论 -
LeetCode 采坑两次后,我终于学会了 BFS
上周末的时候参加 LeetCode 周赛,碰到了一道题。感觉很有意思,而且收获也不小,记录一下。题目链接如下:https://leetcode-cn.com/problems/map-of-highest-peak/题目描述:给你一个大小为 m x n 的整数矩阵 isWater ,它代表了一个由 陆地 和 水域 单元格组成的地图。如果 isWater[i][j] == 0 ,格子 (i, j)是一个 陆地 格子。如果 isWater[i][j] == 1 ,格子 (i, j) 是一个 水域原创 2021-02-22 21:14:54 · 350 阅读 · 0 评论 -
Python3 实战 LeetCode 15.三数之和、18.四数之和,并扩展至 N 数之和
实战 LeetCode 15.三数之和、18.四数之和,并扩展至 N 数之和题目描述15.三数之和链接:https://leetcode-cn.com/problems/3sum/给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组。注意:答案中不可以包含重复的三元组。18.四数之和链接:https://leetcode-cn.com/problems/4sum/给定一个包含 n原创 2021-02-21 21:21:31 · 232 阅读 · 0 评论 -
五千字长文带你学习二分查找算法及其变体
二分查找的思想提及二分查找算法,我想大部分人都不陌生,就算不是学计算机的,基本上也都使用过二分查找的思想,不信的话,且听我慢慢为你道来。不知道你有没有玩过这样一个游戏,猜数字。就是说一个人心里想了一个数字,这个数字有范围,然后另外一个人去猜,每次猜的时候,另一个人会告诉你是猜的大了,还是小了,亦或是猜中了,看怎么样才能够最快的猜中另一个人想的数字。想必大部分人都玩过吧,比如说,数字范围是 0 - 100,那我想你肯定是先猜 50,如果说猜大了,那就去猜 25,否则去猜 75, 以此类推,直到被猜的区间原创 2020-11-29 14:29:57 · 225 阅读 · 0 评论 -
LeetCode(力扣) 1648. 销售价值减少的颜色球,完美结合二分算法和贪心算法
一个二分查找算法和贪心算法结合的场景之所以写这个,是因为我前两周在参加 LeetCode 周赛的时候,碰到了一个这样题,题目链接如下:1648. 销售价值减少的颜色球1648. 销售价值减少的颜色球你有一些球的库存 inventory ,里面包含着不同颜色的球。一个顾客想要 任意颜色 总数为 orders 的球。这位顾客有一种特殊的方式衡量球的价值:每个球的价值是目前剩下的 同色球 的数目。比方说还剩下 6 个黄球,那么顾客买第一个黄球的时候该黄球的价值为 6 。这笔交易以后,只剩下 5 个原创 2020-11-28 22:26:55 · 580 阅读 · 0 评论 -
LeetCode 10. Regular Expression Matching [正则表达式匹配] Python3
LeetCode 10. Regular Expression Matching [正则表达式匹配] Python3Description点击查看题目Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.‘.’ Match...原创 2020-02-12 17:52:02 · 219 阅读 · 0 评论 -
LeetCode 9. Palindrome Number [回文数] Python3
LeetCode 9. Palindrome Number [回文数] Python3Description点击查看题目Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 12...原创 2020-02-06 20:27:52 · 203 阅读 · 0 评论 -
LeetCode 8. String to Integer [字符串转换整数] (atoi) Python3
LeetCode 8. 字符串转换整数[String to Integer] (atoi) Python3Description点击查看题目Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary un...原创 2020-02-06 19:38:37 · 216 阅读 · 0 评论 -
LeetCode 7. Reverse Integer Python3
LeetCode 7. Reverse Integer Python3Description点击查看题目Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Inp...原创 2020-01-30 15:01:06 · 179 阅读 · 0 评论 -
LeetCode 6. ZigZag Conversion Python3
LeetCode 6. ZigZag Conversion Python3Description点击查看题目The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixe...原创 2020-01-29 13:21:06 · 255 阅读 · 0 评论 -
LeetCode 5. Longest Palindromic Substring Python3
LeetCode 5. Longest Palindromic Substring Python3Description点击查看题目Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Inpu...原创 2020-01-28 20:16:56 · 126 阅读 · 0 评论 -
LeetCode 4. Median of Two Sorted Arrays Python3
LeetCode 4. Median of Two Sorted Arrays Python3Description点击查看题目There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run t...原创 2020-01-28 11:56:27 · 359 阅读 · 0 评论 -
leetcode 3. Longest Substring Without Repeating Characters Python3
leetcode 3. Longest Substring Without Repeating Characters PythonDescription点击查看题目Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcab...原创 2020-01-22 12:00:01 · 188 阅读 · 0 评论 -
leetcode 2. Add Two Numbers Python3
leetcode 2. Add Two Numbers PythonDescription点击查看题目You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes c...原创 2020-01-20 12:05:40 · 286 阅读 · 0 评论 -
leetcode 1. Two Sum Python3
leetcode 1. Two Sum PythonDescriptionGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one ...原创 2020-01-16 12:47:07 · 265 阅读 · 0 评论