[LeetCode] Substring with Concatenation of All Words 串联所有单词的子串
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a conca...
LeetCode 笔记系列13 Jump Game II [去掉不必要的计算]
题目: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your ma...
[LeetCode] 921. Minimum Add to Make Parentheses Valid 使括号有效的最少添加
Given a string `S` of `'('` and `')'` parentheses, we add the minimum number of parentheses ( `'('` or `')'`, and in any positions ) so that the resul...
LeetCode 921. 使括号有效的最少添加(Minimum Add to Make Parentheses Valid) 48
921. 使括号有效的最少添加921. Minimum Add to Make Parentheses Valid题目描述给定一个由 '(' 和 ')' 括号组成的字符串 S,我们需要添加最少的括号( '(' 或是 ')',可以在任何位置),以使得到的括号字符串有效。从形式上讲,只有满足下面几点之一...
【LeetCode】921. Minimum Add to Make Parentheses Valid 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/目录题目描述题目大意解题方法日期题目地址: https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/题目描述G...
[LeetCode] 4 Keys Keyboard 四键的键盘
Imagine you have a special keyboard with the following keys:Key 1: (A): Print one 'A' on screen.Key 2: (Ctrl-A): Select the whole screen.Key 3: (Ctrl-...
Golang | Leetcode Golang题解之第59题螺旋矩阵II-题解:
func generateMatrix(n int) [][]int { matrix := make([][]int, n) for i := range matrix { matrix[i] = make([]int, n) } num := 1 l...
(LeetCode)用两个栈实现一个队列
LeetCode上面的一道题目。原文例如以下:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the ...
【算法】【贪心算法】【leetcode】870. 优势洗牌
题目地址:https://leetcode.cn/problems/advantage-shuffle/description/ 题目描述: 给定两个长度相等的数组 nums1 和 nums2,nums1 相对于 nums2 的优势可以用满足 nums1[i] > nums2[i] 的索...
LeetCode in Python 74/240. Search a 2D Matrix I/II (搜索二维矩阵I/II)
搜索二维矩阵I其实可以转换为搜索一维数组,原因在于,只要先确定搜索的整数应该在哪一行,即可对该行进行二分查找。 搜索二维矩阵II中矩阵元素排列方式与I不同,但思想大致相同。 目录 LeetCode in Python 74. LeetCode in Python 240. LeetCode in ...
leetcode-686-Repeated String Match(重复多少次A能够找到B)
题目描述:Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1...
LeetCode154.寻找旋转排序数组中的最小值 II
154.寻找旋转排序数组中的最小值 II描述假设按照升序排序的数组在预先未知的某个点上进行了旋转。( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。请找出其中最小的元素。注意数组中可能存在重复的元素。示例示例 1:输入: [1,3,5]输出: 1示例 2:...
Java for LeetCode 145 Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1...
Leetcode: Mini Parser
Given a nested list of integers represented as a string, implement a parser to deserialize it.Each element is either an integer, or a list -- whose el...
LeetCode 刷题 -- Day 5
今日题目 题目难度备注232. 用栈实现队列 简单225. 用队列实现栈简单20. 有效的括号 简单1047. 删除字符串中的所有相邻重复项简单有所得:string也为栈150. 逆波兰表达式求值中等239. 滑动窗口最大值 困难通过模拟优化代码347. 前 K 个高频元素中等⭐⭐⭐ 栈和队列篇...
Binary Tree Paths leetcode
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1-&...
【Leetcode每日一题】 动态规划 - 简单多状态 dp 问题 - 打家劫舍 II(难度⭐⭐)(67)
1. 题目解析 题目链接:213. 打家劫舍 II 这个问题的理解其实相当简单,只需看一下示例,基本就能明白其含义了。 2.算法原理 这个问题是经典的“打家劫舍”问题的变种,原问题是在单排房屋中进行偷窃,而这个问题则是在环形排列的房屋中进行。环形排列的特点在于首尾相连,这为我们设计算法带来了新的挑...
Leetcode 334. Increasing Triplet Subsequence-Algorithm
Dynamic Programming (DP). Following the increasing length of tuples, scan the array from front to back each time, saving the position of the smallest
leetcode48 旋转图像
class Solution: def rotate(self, matrix: List[List[int]]) -> None: n = len(matrix) for i in range(n // 2): for j in r...
Leetcode—1017. 负二进制转换【中等】(string列表初始化、反向迭代器)
2024每日刷题(120) Leetcode—1017. 负二进制转换 实现代码 class Solution {public: string baseNeg2(int n) { string ans; while(n != 0) { ans...