consecutive leetcode moving stones

LeetCode952三部曲之二:小幅度优化(137ms -> 122ms,超39% -> 超51%)

### 欢迎访问我的GitHub > 这里分类和汇总了欣宸的全部原创(含配套源码):[https://github.com/zq2599/blog_demos](https://github.com/zq2599/blog_demos) ### 本篇概览 - 本文是《LeetCode952三部曲》系 ......
三部曲 幅度 LeetCode ms 952

leetcode139 单词拆分

下面采用穷举的方法。但是超时。 注意:题目示例中看起来输出是字符串‘true’or'false'。但是实际输出是bool类型,所以在下面程序中进行了转换。 class Solution: def __init__(self): self.ans='false' def wordBreak(self, ......
单词 leetcode 139

leetcode226 翻转二叉树——简单

# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self. ......
leetcode 226

leetcode题库39.组合总和——递归 穷举

class Solution: def combinationSum(self, candidates, target): res,ans=[],[] def findpath(candidates): if sum(ans)==target: res.append(ans.copy()) retu ......
题库 总和 leetcode 39

[LeetCode] 2707. Extra Characters in a String

You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that eac ......
Characters LeetCode String Extra 2707

[LeetCode] 1921. Eliminate Maximum Number of Monsters

You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, whe ......
Eliminate LeetCode Monsters Maximum Number

Leetcode 剑指 Offer 58 - II. 左旋转字符串(Zuo xuan zhuan zi fu chuan lcof)

[题目链接](https://leetcode.cn/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof) 字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如,输入字符串"abcdefg"和数字2,该函数将返回 ......
左旋 字符串 字符 Leetcode Offer

Leetcode刷题笔记——二分法

二分法是搜索算法中极其典型的方法,其要求输入序列有序并可随机访问。算法思想为 输入:有序数组nums,目的数值target 要求输出:如果target存在在数组中,则输出其index,否则输出-1 1. 将原数组通过[left,right]两个索引划分范围,初值left=0,right=数组的最后一 ......
二分法 Leetcode 笔记

LeetCode952三部曲之一:解题思路和初级解法(137ms,超39%)

### 欢迎访问我的GitHub > 这里分类和汇总了欣宸的全部原创(含配套源码):[https://github.com/zq2599/blog_demos](https://github.com/zq2599/blog_demos) ### 题目描述 - 难度:**困难** - 编程语言:Jav ......
解法 三部曲 LeetCode 思路 952

[LeetCode] 1560. Most Visited Sector in a Circular Track

Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on t ......
LeetCode Circular Visited Sector Track

[LeetCode] 2511. Maximum Enemy Forts That Can Be Captured

You are given a 0-indexed integer array forts of length n representing the positions of several forts. forts[i] can be -1, 0, or 1 where: -1 represent ......
LeetCode Captured Maximum Enemy Forts

【Leetcode刷题记录】1、买钢笔和铅笔的方案数;2、一个图中连通三元组的最小度数;3、带因子的二叉树

1、买钢笔和铅笔的方案数 题目:给你一个整数 total ,表示你拥有的总钱数。同时给你两个整数 cost1 和 cost2 ,分别表示一支钢笔和一支铅笔的价格。你可以花费你部分或者全部的钱,去买任意数目的两种笔。 请你返回购买钢笔和铅笔的 不同方案数目 。 思路:枚举法。 假设 total 最多可 ......
度数 钢笔 因子 铅笔 Leetcode

[LeetCode][494]target-sum

# Content You are given an integer array nums and an integer target. You want to build an expression out of nums by adding one of the symbols '+' and ......
target-sum LeetCode target 494 sum

[LeetCode][416]partition-equal-subset-sum

# Content Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets i ......

Leetcode 151. 反转字符串中的单词(Reverse words in a string)

[题目链接](https://leetcode.cn/problems/reverse-words-in-a-string) 给你一个字符串 s ,请你反转字符串中 单词 的顺序。 单词 是由非空格字符组成的字符串。s 中使用至少一个空格将字符串中的 单词 分隔开。 返回 单词 顺序颠倒且 单词 之 ......
字符串 单词 字符 Leetcode Reverse

LeetCode46全排列(回溯入门)

### 欢迎访问我的GitHub > 这里分类和汇总了欣宸的全部原创(含配套源码):[https://github.com/zq2599/blog_demos](https://github.com/zq2599/blog_demos) ### 题目描述 - 难度:中等 - 给定一个不含重复数字的数 ......
LeetCode 46

[LeetCode] 2240. Number of Ways to Buy Pens and Pencils

You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen ......
LeetCode Pencils Number 2240 Ways

Leetcode 24. 两两交换链表中的节点(Swap nodes in pairs)

[题目链接](https://leetcode.cn/problems/swap-nodes-in-pairsn/) 给你一个链表,两两交换其中相邻的节点,并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题(即,只能进行节点交换)。 示例 1: ![](https://img202 ......
节点 Leetcode nodes pairs Swap

[LeetCode][338]counting-bits

# Content Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary repres ......
counting-bits LeetCode counting bits 338

[LeetCode][337]house-robber-iii

# Content The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root. Besides the root, each ......
house-robber-iii LeetCode robber house 337

[LeetCode][322]coin-change

# Content You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of mone ......
coin-change LeetCode change coin 322

[LeetCode][312]burst-balloons

# Content You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked t ......
burst-balloons LeetCode balloons burst 312

[LeetCode] 2483. Minimum Penalty for a Shop

You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y': if the ith chara ......
LeetCode Minimum Penalty 2483 Shop

leetcode & c++多线程刷题日志

## 1.按序打印 [按序打印](https://leetcode.cn/problems/print-in-order/description/) **解法** + 1. 互斥锁 ```c++ class Foo { mutex mtx1, mtx2; public: Foo() { mtx1.l ......
线程 leetcode 日志 amp

Leetcode刷题笔记——单调性

## 单调性 单调性是数学中使用的一种常见性质,通常用于描述函数,在高等数学中的定义常常为: 设函数f(x)在区间I上有定义,如果对于I上的任意两个数x1和x2,当x1f(x2)),则称函数f(x)在区间I上是单调递增的(或者单调递减的)。 例如如下图像就是两个单调函数。 ![](https://i ......
Leetcode 笔记

Leetcode 剑指Offer 05. 替换空格(Ti huan kong ge lcof)

[题目链接](https://leetcode.cn/problems/ti-huan-kong-ge-lcof) 请实现一个函数,把字符串 s 中的每个空格替换成"%20"。 示例 1: ``` 输入:s = "We are happy." 输出:"We%20are%20happy." ``` 提 ......
空格 Leetcode Offer huan kong

[LeetCode][309]best-time-to-buy-and-sell-stock-with-cooldown

# Content You are given an array prices where prices[i] is the price of a given stock on the ith day. Find the maximum profit you can achieve. You may ......

[LeetCode 11]盛最多水的容器 二分

emmm看到这题第一反应是二分_(:з」∠)_ 首先可以观察到,假设我们目前敲定了2块板l和r,那么在l和r之间,低于l和r的板子都是无效的(这个应该显而易见)。 基于这个性质对无效板进行消除,最后会得到一个山峰形(先单调不降,后单调不升) 现在考虑对山峰形如何求解。 考虑枚举每个有效板作为边界,寻 ......
容器 LeetCode 11

理解move

```cpp #include #include #include #include using namespace std; struct B { int v = 100; ~B() { v = 0; } }; struct A { A(B* p) { aa = p; } B* aa = null ......
move

Leetcode刷题之 1071. 字符串的最大公因子

# 题目描述 对于字符串 s 和 t,只有在 s = t + ... + t(t 自身连接 1 次或多次)时,我们才认定 “t 能除尽 s”。 给定两个字符串 str1 和 str2 。返回 最长字符串 x,要求满足 x 能除尽 str1 且 x 能除尽 str2 。 示例 1: 输入:str1 = ......
因子 字符串 字符 Leetcode 1071