自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Python内置函数 Leetcode刷题总结(持续更新)

str.isalpha(): 判断字符串是否只由字母组成^异或 1<<5,相当于把第5位从0变到1,从1变到0, 即实现大小写的转换0 ^ 0=0 , 0 ^ 1= 1 , 1 ^ 0= 1 , 1 ^ 1= 0ord()返回对应的ASCII码chr()返回对应的ASCII字符itertools.product(a,b): 笛卡尔积...

2020-05-09 04:31:11 980 1

原创 Python常用场景

【代码】Python常用场景。

2024-03-09 17:12:12 339

原创 算法刷题-二分法

查左边界:=时,收缩right。查右边界:=时,收缩left。

2024-03-09 17:11:09 323

原创 算法(数据结构)面试问题准备 二分法/DFS/BFS/快排

二分法-Leetcode刷题面试

2024-03-09 17:10:06 780 1

原创 C++核心概念

此为学习笔记,教程链接为https://www.bilibili.com/video/BV1et411b73Z?p=841. 内存分区代码区共享、只读全局区:全局变量、静态变量(static)、常量(字符串、const修饰的全局常量)栈区:编译器自动分配释放,如函数参数值、局部变量不要返回局部变量的地址,栈区数据在函数执行后自动释放堆区:程序员分配释放,程序结束时系统也会回收用new在堆区开辟内存:int* p = new int(10);释放:delete p;, d.

2020-12-29 01:27:40 313 1

原创 C++基本语法

框架#include <iostream>using namespace std;int main(){ cout << "hello world" << endl; // print system("pause"); return 0;}定义#define PI 3.14const float pi = 3.14;快捷键注释:Ctrl + K + C取消注释:Ctrl + K + U设置断点:F9全局自动排版:Ctrl + K

2020-12-23 05:13:35 212

原创 Leetcode-1019. 链表中的下一个更大节点 -Python

题目给出一个以头节点 head 作为第一个节点的链表。链表中的节点分别编号为:node_1, node_2, node_3, … 。每个节点都可能有下一个更大值(next larger value):对于 node_i,如果其 next_larger(node_i) 是 node_j.val,那么就有 j > i 且 node_j.val > node_i.val,而 j 是可能的选项中最小的那个。如果不存在这样的 j,那么下一个更大值为 0 。返回整数答案数组 answer,其中 a

2020-08-25 03:29:57 243

原创 Leetcode-556. 下一个更大元素 III -python

题目给定一个32位正整数 n,你需要找到最小的32位整数,其与 n 中存在的位数完全相同,并且其值大于n。如果不存在这样的32位整数,则返回-1。链接:https://leetcode-cn.com/problems/next-greater-element-iii/Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits exi

2020-08-25 03:22:23 232

原创 Leetcode-877. 石子游戏 486. 预测赢家 (动态规划) -python

题目亚历克斯和李用几堆石子在做游戏。偶数堆石子排成一行,每堆都有正整数颗石子 piles[i] 。游戏以谁手中的石子最多来决出胜负。石子的总数是奇数,所以没有平局。亚历克斯和李轮流进行,亚历克斯先开始。 每回合,玩家从行的开始或结束处取走整堆石头。 这种情况一直持续到没有更多的石子堆为止,此时手中石子最多的玩家获胜。假设亚历克斯和李都发挥出最佳水平,当亚历克斯赢得比赛时返回 true ,当李赢得比赛时返回 false 。链接:https://leetcode-cn.com/problems/s

2020-08-01 23:22:38 198

原创 Leetcode-307. 区域和检索 - 数组可修改 Range Sum Query - Mutable (线段树Segment Tree)-超详细Python

题目给定一个整数数组 nums,求出数组从索引 i 到 j (i ≤ j) 范围内元素的总和,包含 i, j 两点。update(i, val) 函数可以通过将下标为 i 的数值更新为 val,从而对数列进行修改。链接:https://leetcode.com/problems/range-sum-query-mutable/Given an integer array nums, find the sum of the elements between indices i and j (

2020-08-01 09:20:14 236

原创 Leetcode-75. 颜色分类 Sort Colors (荷兰国旗问题) -超详细python

题目给定一个包含红色、白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。此题中,我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。注意:不能使用代码库中的排序函数来解决这道题。链接:https://leetcode.com/problems/sort-colors/Given an array with n objects colored red, white or blue, sort them in-place so

2020-07-31 06:04:33 204

原创 Leetcode-1040. 移动石子直到连续 II Moving Stones Until Consecutive II (滑动窗口) -超详细python

题目在一个长度无限的数轴上,第 i 颗石子的位置为 stones[i]。如果一颗石子的位置最小/最大,那么该石子被称作端点石子。每个回合,你可以将一颗端点石子拿起并移动到一个未占用的位置,使得该石子不再是一颗端点石子。值得注意的是,如果石子像 stones = [1,2,5] 这样,你将无法移动位于位置 5 的端点石子,因为无论将它移动到任何位置(例如 0 或 3),该石子都仍然会是端点石子。当你无法进行任何移动时,即,这些石子的位置连续时,游戏结束。要使游戏结束,你可以执行的最小和最大移动次数

2020-07-31 05:57:12 264

原创 Leetcode-894. 所有可能的满二叉树 All Possible Full Binary Trees

题目满二叉树是一类二叉树,其中每个结点恰好有 0 或 2 个子结点。返回包含 N 个结点的所有可能满二叉树的列表。 答案的每个元素都是一个可能树的根结点。答案中每个树的每个结点都必须有 node.val=0。你可以按任何顺序返回树的最终列表。链接:https://leetcode.com/problems/all-possible-full-binary-trees/A full binary tree is a binary tree where each node has exactly

2020-07-31 03:07:03 146

原创 Leetcode-990. 等式方程的可满足性 Satisfiability of Equality Equations (并查集) -超详细python

题目给定一个由表示变量之间关系的字符串方程组成的数组,每个字符串方程 equations[i] 的长度为 4,并采用两种不同的形式之一:“a==b” 或 “a!=b”。在这里,a 和 b 是小写字母(不一定不同),表示单字母变量名。只有当可以将整数分配给变量名,以便满足所有给定的方程时才返回 true,否则返回 false。链接:https://leetcode.com/problems/satisfiability-of-equality-equations/Given an array eq

2020-06-18 03:19:19 159

原创 Leetcode-399. 除法求值 Evaluate Division (并查集Union-Find) -超详细python

题目给出方程式 A / B = k, 其中 A 和 B 均为用字符串表示的变量, k 是一个浮点型数字。根据已知方程式求解问题,并返回计算结果。如果结果不存在,则返回 -1.0。链接:https://leetcode.com/problems/evaluate-division/Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a rea

2020-06-17 03:21:57 296

原创 Leetcode-802. 找到最终的安全状态 Find Eventual Safe State (拓扑排序) -python

题目在有向图中, 我们从某个节点和每个转向处开始, 沿着图的有向边走。 如果我们到达的节点是终点 (即它没有连出的有向边), 我们停止。现在, 如果我们最后能走到终点,那么我们的起始节点是最终安全的。 更具体地说, 存在一个自然数 K, 无论选择从哪里开始行走, 我们走了不到 K 步后必能停止在一个终点。哪些节点最终是安全的? 结果返回一个有序的数组。该有向图有 N 个节点,标签为 0, 1, …, N-1, 其中 N 是 graph 的节点数. 图以以下的形式给出: graph[i] 是节点

2020-06-13 02:36:08 203

原创 Leetcode-207. 课程表 Course Schedule (拓扑排序) -超详细python

题目你这个学期必须选修 numCourse 门课程,记为 0 到 numCourse-1 。在选修某些课程之前需要一些先修课程。 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们:[0,1]给定课程总量以及它们的先决条件,请你判断是否可能完成所有课程的学习?链接:https://leetcode.com/problems/course-schedule/There are a total of numCourses courses you have to take,

2020-06-10 03:00:16 289

原创 Leetcode-518. 零钱兑换 II Coin Change 2 (DP) -超详细python

题目给定不同面额的硬币和一个总金额。写出函数来计算可以凑成总金额的硬币组合数。假设每一种面额的硬币有无限个。链接:https://leetcode.com/problems/coin-change-2/You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that a

2020-06-08 04:42:12 192

原创 Leetcode-1202. 交换字符串中的元素 Smallest String With Swaps (并查集/DFS) -超详细python

题目给你一个字符串 s,以及该字符串中的一些「索引对」数组 pairs,其中 pairs[i] = [a, b] 表示字符串中的两个索引(编号从 0 开始)。你可以 任意多次交换 在 pairs 中任意一对索引处的字符。返回在经过若干次交换后,s 可以变成的按字典序最小的字符串。链接:https://leetcode.com/problems/smallest-string-with-swaps/You are given a string s, and an array of pairs o

2020-06-08 04:37:51 333

原创 Leetcode-406. Queue Reconstruction by Height 根据身高重建队列 -python

题目假设有打乱顺序的一群人站成一个队列。 每个人由一个整数对(h, k)表示,其中h是这个人的身高,k是排在这个人前面且身高大于或等于h的人数。 编写一个算法来重建这个队列。链接:https://leetcode.com/problems/queue-reconstruction-by-height/Suppose you have a random list of people standing in a queue. Each person is described by a pair of

2020-06-07 07:41:21 164

原创 Leetcode-841. Keys and Rooms 钥匙和房间 (DFS/BFS) -python

题目有 N 个房间,开始时你位于 0 号房间。每个房间有不同的号码:0,1,2,…,N-1,并且房间里可能有一些钥匙能使你进入下一个房间。在形式上,对于每个房间 i 都有一个钥匙列表 rooms[i],每个钥匙 rooms[i][j] 由 [0,1,…,N-1] 中的一个整数表示,其中 N = rooms.length。 钥匙 rooms[i][j] = v 可以打开编号为 v 的房间。最初,除 0 号房间外的其余所有房间都被锁住。你可以自由地在房间之间来回走动。如果能进入每个房间返回 true

2020-06-06 03:16:39 203

原创 Leetcode-1162. As Far from Land as Possible 地图分析 (BFS) -python

题目你现在手里有一份大小为 N x N 的「地图」(网格) grid,上面的每个「区域」(单元格)都用 0 和 1 标记好了。其中 0 代表海洋,1 代表陆地,请你找出一个海洋区域,这个海洋区域到离它最近的陆地区域的距离是最大的。我们这里说的距离是「曼哈顿距离」( Manhattan Distance):(x0, y0) 和 (x1, y1) 这两个区域之间的距离是 |x0 - x1| + |y0 - y1| 。如果我们的地图上只有陆地或者海洋,请返回 -1。链接:https://leetcode

2020-06-06 03:04:23 197

原创 Leetcode-1302. Deepest Leaves Sum 层数最深叶子节点的和 -python

题目给你一棵二叉树,请你返回层数最深的叶子节点的和。链接:https://leetcode.com/problems/deepest-leaves-sum/Given a binary tree, return the sum of values of its deepest leaves.Example:Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]Output: 15思路及代码DFS# Definition f

2020-06-05 03:46:12 154

原创 Leetcode-987. Vertical Order Traversal of a Binary Tree 二叉树的垂序遍历 -python

题目给定二叉树,按垂序遍历返回其结点值。对位于 (X, Y) 的每个结点而言,其左右子结点分别位于 (X-1, Y-1) 和 (X+1, Y-1)。把一条垂线从 X = -infinity 移动到 X = +infinity ,每当该垂线与结点接触时,我们按从上到下的顺序报告结点的值( Y 坐标递减)。如果两个结点位置相同,则首先报告的结点值较小。按 X 坐标顺序返回非空报告的列表。每个报告都有一个结点值列表。链接:https://leetcode.com/problems/vertical-

2020-06-05 03:38:08 179

原创 Leetcode-96. Unique Binary Search Trees 不同的二叉搜索树 (DP) -python

题目给定一个整数 n,求以 1 … n 为节点组成的二叉搜索树有多少种?链接:https://leetcode.com/problems/unique-binary-search-trees/Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?Example:Input: 3Output: 5Explanation:Given n = 3, there are

2020-06-03 03:25:22 144

原创 Leetcode-1048. Longest String Chain 最长字符串链 (DP) -python

题目给出一个单词列表,其中每个单词都由小写英文字母组成。如果我们可以在 word1 的任何地方添加一个字母使其变成 word2,那么我们认为 word1 是 word2 的前身。例如,“abc” 是 “abac” 的前身。词链是单词 [word_1, word_2, …, word_k] 组成的序列,k >= 1,其中 word_1 是 word_2 的前身,word_2 是 word_3 的前身,依此类推。从给定单词列表 words 中选择单词组成词链,返回词链的最长可能长度。链接:ht

2020-06-02 23:09:22 319

原创 Leetcode-152. Maximum Product Subarray 乘积最大子数组 (DP) -python

题目给你一个整数数组 nums ,请你找出数组中乘积最大的连续子数组(该子数组中至少包含一个数字),并返回该子数组所对应的乘积。链接:https://leetcode.com/problems/maximum-product-subarray/Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest

2020-06-01 22:40:44 144

原创 Leetcode-673. Number of Longest Increasing Subsequence 最长递增子序列的个数 (DP) -python

题目给定一个未排序的整数数组,找到最长递增子序列的个数。链接:https://leetcode.com/problems/number-of-longest-increasing-subsequence/Given an unsorted array of integers, find the number of longest increasing subsequence.Example:Input: [1,3,5,4,7]Output: 2Explanation: The two l

2020-05-31 04:07:15 178

原创 Leetcode-300. Longest Increasing Subsequence 最长上升子序列 (经典DP) -python

题目给定一个无序的整数数组,找到其中最长上升子序列的长度。链接:https://leetcode.com/problems/longest-increasing-subsequence/Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4Explanation: The long

2020-05-31 03:05:39 154

原创 Leetcode-140. Word Break II 单词拆分 II (DP)

题目给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,在字符串中增加空格来构建一个句子,使得句子中所有的单词都在词典中。返回所有这些可能的句子。链接:https://leetcode.com/problems/word-break-ii/Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a

2020-05-30 04:35:44 117

原创 Leetcode-139. Word Break 单词拆分(DP)

题目给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。链接:https://leetcode.com/problems/word-break/Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-sep

2020-05-30 03:33:44 141

原创 Leetcode-79. Word Search 单词搜索

题目给定一个二维网格和一个单词,找出该单词是否存在于网格中。单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。链接:https://leetcode.com/problems/word-search/Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from lette

2020-05-29 04:47:49 133

原创 Leetcode-37. Sudoku Solver 解数独

题目编写一个程序,通过已填充的空格来解决数独问题。链接:https://leetcode.com/problems/sudoku-solver/Write a program to solve a Sudoku puzzle by filling the empty cells.A sudoku solution must satisfy all of the following rules:Each of the digits 1-9 must occur exactly once in

2020-05-29 03:38:57 187

原创 Leetcode-22. Generate Parentheses 括号生成 -python

题目数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。链接:https://leetcode.com/problems/generate-parentheses/Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Example:Input:n=3Output:[“((()))”,“(()

2020-05-29 02:49:30 125

原创 Leetcode-162. Find Peak Element 寻找峰值 (二分查找) -python

题目峰值元素是指其值大于左右相邻值的元素。给定一个输入数组 nums,其中 nums[i] ≠ nums[i+1],找到峰值元素并返回其索引。数组可能包含多个峰值,在这种情况下,返回任何一个峰值所在位置即可。你可以假设 nums[-1] = nums[n] = -∞。链接:https://leetcode.com/problems/find-peak-element/A peak element is an element that is greater than its neighbors

2020-05-28 04:00:12 370

原创 Leetcode-154. Find Minimum in Rotated Sorted Array II 寻找旋转排序数组中的最小值 II (二分查找) -python

题目假设按照升序排序的数组在预先未知的某个点上进行了旋转。( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。请找出其中最小的元素。注意数组中可能存在重复的元素。链接:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/submissions/Suppose an array sorted in ascending order is rotated at some

2020-05-28 03:48:30 140

原创 Leetcode-153. Find Minimum in Rotated Sorted Array 寻找旋转排序数组中的最小值 (二分查找) -python

题目假设按照升序排序的数组在预先未知的某个点上进行了旋转。( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。请找出其中最小的元素。你可以假设数组中不存在重复元素。链接:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/Suppose an array sorted in ascending order is rotated at some pivot unknown

2020-05-28 03:37:53 168

原创 Leetcode-81. Search in Rotated Sorted Array II 搜索旋转排序数组 II (二分查找) -python

题目假设按照升序排序的数组在预先未知的某个点上进行了旋转。( 例如,数组 [0,0,1,2,2,5,6] 可能变为 [2,5,6,0,0,1,2] )。编写一个函数来判断给定的目标值是否存在于数组中。若存在返回 true,否则返回 false。链接:https://leetcode.com/problems/search-in-rotated-sorted-array-ii/Suppose an array sorted in ascending order is rotated at som

2020-05-28 03:24:10 140

原创 Leetcode-33. Search in Rotated Sorted Array 搜索旋转排序数组 (二分查找) -python

题目假设按照升序排序的数组在预先未知的某个点上进行了旋转。( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。搜索一个给定的目标值,如果数组中存在这个目标值,则返回它的索引,否则返回 -1 。你可以假设数组中不存在重复的元素。链接:https://leetcode.com/problems/search-in-rotated-sorted-array/Suppose an array sorted in ascending order is rota

2020-05-28 03:06:53 164

原创 Leetcode-981. Time Based Key-Value Store 基于时间的键值存储 (二分法)-python

题目创建一个基于时间的键值存储类 TimeMap,它支持下面两个操作:1.set(string key, string value, int timestamp)-存储键 key、值 value,以及给定的时间戳 timestamp。2.get(string key, int timestamp)-返回先前调用 set(key, value, timestamp_prev) 所存储的值,其中 timestamp_prev <= timestamp。-如果有多个这样的值,则返回对应最大的

2020-05-26 03:38:30 224

空空如也

空空如也

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

TA关注的人

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