leetcode winner array 1535
leetcode1161最大层内元素之和
dfs lass Solution { public: unordered_map<int,vector<int>>m; void dfs(TreeNode* root,int depth){ if(!root)return; int res=0; depth++; dfs(root->left,d ......
【题解】CF1852B Imbalanced Arrays
我们假设当前出长度为 $len$,那么我们在序列中一定有一个 $len/0$,因为一定有一个绝对值最大的数,如果这个数是正数在原序列中就是 $len$,是负数在原序列中即为 $0$。 由上文,我们可以得到,一定不能有 $len$ 和 $0$ 同时出现的情况,也一定不能有 $len$ 和 $now$ ......
LeetCode -- 394. 字符串解码(栈处理字符串问题)
我们用栈同时维护当前字符串和倍数以及要加倍的字符串 当遇到"["时,我们保存当前字符串,即将当前字符 cres 串入栈; 当遇到"]"时,res = cres + 倍数 * 应加倍的字符串 class Solution: def decodeString(self, s: str) -> str: ......
【Leetcode刷题记录】1、汇总区间;2、合并区间;3、插入区间
1、汇总区间 题目:给定一个 无重复元素 的 有序 整数数组 nums 。 返回 恰好覆盖数组中所有数字 的 最小有序 区间范围列表 。也就是说,nums 的每个元素都恰好被某个区间范围所覆盖,并且不存在属于某个范围但不属于 nums 的数字 x 。 列表中的每个区间范围 [a,b] 应该按如下格式 ......
力扣——9 [回文数](https://leetcode.cn/problems/two-sum/)
给你一个整数 `x` ,如果 `x` 是一个回文整数,返回 `true` ;否则,返回 `false` 。 回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 - 例如,`121` 是回文,而 `123` 不是。 **示例 1:** ``` 输入:x = 121 输出:true ``` ......
[LeetCode] 2433. Find The Original Array of Prefix Xor
You are given an integer array pref of size n. Find and return the array arr of size n that satisfies: pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]. Note ......
Sort a N sorted array
Given an array of n elements, where each element is at most k away from its target position, you need to sort the array optimally. Example 1: Input: n ......
[Leetcode Weekly Contest]361
title: '[Leetcode Weekly Contest]361' date: 2023-08-21 15:18:48 tags: [OJ] mathjax: true 链接:[LeetCode](https://leetcode-cn.com/contest/weekly-contest- ......
LeetCode952三部曲之三:再次优化(122ms -> 96ms,超51% -> 超91%)
### 欢迎访问我的GitHub > 这里分类和汇总了欣宸的全部原创(含配套源码):[https://github.com/zq2599/blog_demos](https://github.com/zq2599/blog_demos) ### 本篇概览 - 本文是《LeetCode952三部曲之三 ......
[CF1641D] Two Arrays
## 题目描述 Sam changed his school and on the first biology lesson he got a very interesting task about genes. You are given $ n $ arrays, the $ i $ -th o ......
leetcode199二叉树的右视图
前序遍历:中左右(先遍历左子树);中右左(先遍历右子树) 中序遍历:左中右; 后序遍历:左右中; 本题递归: vector<int>v;//记录最先遍历到的右子树 void dfs(TreeNode* root,int depth){ if(!root)return ; if(v.size()==d ......
【Leetcode刷题记录】1、最多可以摧毁的敌人城堡数目;2、消灭怪物的最大数量;3、序列化和反序列化二叉搜索树
1、最多可以摧毁的敌人城堡数目 题目:给你一个长度为 n ,下标从 0 开始的整数数组 forts ,表示一些城堡。forts[i] 可以是 -1 ,0 或者 1 ,其中: -1 表示第 i 个位置 没有 城堡。 0 表示第 i 个位置有一个 敌人 的城堡。 1 表示第 i 个位置有一个你控制的城堡 ......
报错Array to string conversion
### 报错Array to string conversion 原因:数组格式无法存储进数据库 technologies是字段名 ``` use Illuminate\Database\Eloquent\Model; class App extends Model { protected $cas ......
LeetCode 周赛上分之旅 #43 计算机科学本质上是数学吗?
> ⭐️ **本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 \[彭旭锐] 和 [BaguTree Pro](https://www.mdnice.com/writing/85b28c4e60354865a423728e668fc570) 知识星球提问。** > > 学习数据 ......
力扣——1 [两数之和](https://leetcode.cn/problems/two-sum/)
给定一个整数数组 `nums` 和一个整数目标值 `target`,请你在该数组中找出 **和为目标值** *`target`* 的那 **两个** 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案。 **示例 ......
【Leetcode刷题记录】四种买卖股票问题
前言:买卖股票问题大多数都是用动态规划解决,关键在于手上是否有股票,据此来找状态转移方程 1、买卖股票的最佳时机 题目:给定一个数组 prices ,它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。 你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该 ......
20230528 java.lang.reflect.Array
## 介绍 - `java.lang.reflect.Array` - `public final class Array` - 提供创建和访问Java数组的静态方法 ## API ### static - newInstance - 创建一维或多维数组 - getLength get 系列方法 - ......
js操作Array数组大全
unshift:将参数添加到原数组开头,并返回数组的长度 pop:删除原数组最后一项,并返回删除元素的值;如果数组为空则返回undefined push:将参数添加到原数组末尾,并返回数组的长度 concat:返回一个新数组,是将参数添加到原数组中构成的 splice(start,deleteCou ......
刷题[Leetcode]3. 无重复字符的最长子串
3. 无重复字符的最长子串 class Solution { public: int lengthOfLongestSubstring(string s) { if (s.size() == 0) return 0; unordered_set<int> unset; int maxLen = 0; ......
LeetCode952三部曲之二:小幅度优化(137ms -> 122ms,超39% -> 超51%)
### 欢迎访问我的GitHub > 这里分类和汇总了欣宸的全部原创(含配套源码):[https://github.com/zq2599/blog_demos](https://github.com/zq2599/blog_demos) ### 本篇概览 - 本文是《LeetCode952三部曲》系 ......
PHP 中 array_walk 与array_map的区别
# PHP 中 array_walk 与array_map的区别 `array_map` 函数来对数组中的每个元素应用回调函数。该函数与 `array_walk` 类似**,但是它返回一个新的数组,而不是直接修改原始数组。** 在 PHP 中,可以使用 `array_walk` 函数来遍历数组并执行 ......
array
Array Array 对象是用于构造数组的全局对象,数组是类似于列表的高阶对象。 #实例属性 #length length 是 Array 的实例属性,表示该数组中元素的个数。该值是一个无符号 32 位整数,并且其数值总是大于数组最大索引。 const clothing = ['shoes', ' ......
leetcode139 单词拆分
下面采用穷举的方法。但是超时。 注意:题目示例中看起来输出是字符串‘true’or'false'。但是实际输出是bool类型,所以在下面程序中进行了转换。 class Solution: def __init__(self): self.ans='false' def wordBreak(self, ......
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题库39.组合总和——递归 穷举
class Solution: def combinationSum(self, candidates, target): res,ans=[],[] def findpath(candidates): if sum(ans)==target: res.append(ans.copy()) retu ......
[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 ......
[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 ......
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刷题笔记——二分法
二分法是搜索算法中极其典型的方法,其要求输入序列有序并可随机访问。算法思想为 输入:有序数组nums,目的数值target 要求输出:如果target存在在数组中,则输出其index,否则输出-1 1. 将原数组通过[left,right]两个索引划分范围,初值left=0,right=数组的最后一 ......