leetcode 1493. Longest Subarray of 1‘s After Deleting One Element(删除一个元素后‘1‘ 的最大长度)

告别软件轮询!用STM32G474的COMP比较器实现纳秒级硬件过压保护(CubeMX配置详解) 本文详细介绍了如何利用STM32G474的COMP比较器实现纳秒级硬件过压保护,通过CubeMX配置详解,展示了硬件比较器相比传统软件轮询方案在响应时间、CPU占用和可靠性等方面的显著优势。文章还提供了实战配置流程和优化技巧,帮助工程师快速构建高效的硬件保护系统。 阅读详情

请添加图片描述

数组nums仅含 0,1。要在数组中删除一个元素(全1也要删一个)。
返回删除一个元素后,最长的 全1 子数组的长度。

思路:

因为要求的是全1子数组的长度,
又要删除一个元素,如果一些1中间夹杂着一个0,把0删除后就可以把两段1的子数组接起来。
长度为由0隔开的两段子数组的长度之和。

那如果中间夹杂着多个0呢?
一样的处理,还是算由0隔开的两段子数组的长度,连续的0那么0隔开的子数组长度也为0.

所以两两相加(只能删除一个元素,所以只能两段)由0隔开的子数组长度,记下最大值。

有种特殊情况:没有0,全1,那么全1子数组的长度为n, 但是必须删除一个元素,所以最终长度为n-1.

    public int longestSubarray(int[] nums) {
        int n = nums.length;
        int pre0 = -1;
        int cur0 = findNextZero(0, nums);
        if (cur0 == n) return n - 1; //全1的情况

        int res = 0;
        while (cur0 != n) {
            int next0 = findNextZero(cur0 + 1, nums);
            int len = (cur0 - pre0 - 1) + (next0 - cur0 - 1); //两头的0去掉
            
            res = Math.max(res, len);
            
            pre0 = cur0;
            cur0 = next0;
        }
        return res;
    }

    int findNextZero(int from, int[] arr) {
        for (int i = from; i < arr.length; i++) {
            if (arr[i] == 0) {
                return i;
            }
        }
        return arr.length;
    }
【2026年华为暑期实习(AI)-4月22日-第三题- 网络异常流量传播链路溯源】(题目+思路+Java&C++&Python解析+在线测试) 本文提出了一种基于空间距离和流量负载的网络异常传播链检测方法。首先通过曼哈顿距离建立基站间的直接关联关系,形成无向图;然后计算各连通块的总负载,筛选出关键节点;最后在关键节点构成的有向无环图(DAG)中寻找用户数最大的传播路径。算法采用DFS/BFS识别连通块,并通过动态规划求解最长路径,时间复杂度为O(N^2)。该方法适用于监控网络中异常流量的定向传播分析,能有效识别高负载区域和最大影响路径。 阅读详情

相关推荐

驱动兼容_FANUC 驱动器兼容问题探讨

近10年来,FANUC伺服驱动器随着系统的升级而升级,不同的系统,可以兼容很多种类的驱动器,作者做了一些常见经验总结如下表:电源模块伺服放大器主轴放大器bi一体18i/OIB/OIC6110-Hxxx6114-Hxxx6111-Hxxx6134-Hxxx31iA/OID6140-Hxxx6117-Hxxx6141-Hxxx6164-Hxxx31IB/35IB/OIF/OI MATE D(5包)62...

weixin_34420941的博客 1758

LeetCode1493. 删掉一个元素以后全为 1 的最长子数组 [Medium]

删掉一个元素,返回最长的且只包含 1 的非空子数组的长度。

grllery的博客 1215

无耳科技 Solon v3.0.8 发布,Java 企业级应用开发框架

Solon 是新一代,Java 企业级应用开发框架。是杭州无耳科技有限公司的“根级”开源项目(最近“杭州六小龙”很火啊,我们也是杭州的哦)。从零开始构建(No Spring、No Java-EE、No Servlet),有灵活的接口规范与开放生态。采用对商用友好的 Apache 2.0 开源协议。

向往自由的少年!(我是一个少年!!!) 1707

Leetcode-1493删掉一个元素以后全为 1 的最长子数组

摘要:本文介绍了一道LeetCode滑动窗口题目,要求在二进制数组中删除一个元素后找到最长连续1的子数组。主要思路是维护一个窗口,记录遇到0的次数。当遇到第一个0时继续扩展窗口,遇到第二个0时调整窗口左边界。使用计数器记录1的数量,最终返回最大值。C++实现中考虑了全1数组的特殊情况,时间复杂度为O(n)。代码展示了窗口滑动和条件判断的核心逻辑,适用于类似子数组问题。

m0_67281377的博客 239

Cartographer从安装到实战:手把手教你运行2D/3D建图与定位

本文提供了一份详尽的Cartographer从零安装到实战应用的完整指南。内容涵盖环境准备、依赖编译、源码构建等关键步骤,并手把手指导读者运行2D/3D官方数据集进行建图与定位测试。文章深入解析了参数配置与自定义数据适配方法,帮助开发者快速掌握这一强大的实时同步定位与建图工具,并将其应用于机器人导航与自动驾驶等实际场景。

rice5的博客 957

AI+Xmind自动生成测试用例(思维导图格式)

最后:我是Walker,一个热爱分享编程知识的程序员,希望能够帮助到你!

Think_and_work的博客 2344

leetcode - 1493. Longest Subarray of 1‘s After Deleting One Element

leetcode - 1493

sinat_41679123的博客 296

(十一)随机性与独立性回顾

随机性与独立性回顾

旺旺的碎冰冰~的博客 1023

LeetCode每日一题(Longest Subarray of 1‘s After Deleting One Element)

Given a binary array nums, you should delete one element from it. Return the size of the longest non-empty subarray containing only 1’s in the resulting array. Return 0 if there is no such subarray. Example 1: Input: nums = [1,1,0,1] Output: 3 Explanation:

wangjun861205的博客 169

Android软键盘系统深度解析:架构、原理与实现

Android软键盘系统深度解析:架构与实现原理 本文系统剖析了Android软键盘的核心工作机制。作为系统级输入服务,软键盘具有双重属性:既是可安装的独立应用,又深度集成于系统框架中。文章详细解读了软键盘的系统架构,包括其与InputMethodManagerService(IMMS)和WindowManagerService(WMS)的交互机制,以及通过InputConnection实现的跨进程通信流程。同时分析了输入法窗口的特殊管理策略、布局调整模式,并深入探讨了输入预测引擎的实现原理,包括词典加载、

保持专注,保持热爱 124

基于YOLOv5的仪表读数识别系统:从检测到识别的完整解决方案

随着工业自动化水平的不断提高,仪表读数识别技术在电力系统、石油化工、智能制造等领域发挥着越来越重要的作用。本文提出了一种基于YOLOv5的仪表自动读数识别系统,该系统能够有效区分指针式和数字式仪表,并实现高精度的读数识别。我们详细介绍了系统的整体架构、数据集构建、模型训练策略以及用户界面设计,并提供了完整的代码实现。实验结果表明,本系统在仪表检测和读数识别任务上均取得了优异的表现,为工业现场的自动化监控提供了可靠的技术支持。关键词:仪表读数识别;YOLOv5;目标检测;深度学习;工业自动化。

YOLO 684

1493. Longest Subarray of 1‘s After Deleting One Element

Longest Subarray of 1’s After Deleting One Element Given a binary array nums, you should delete one element from it. Return the size of the longest non-empty subarray containing only 1’s in the resulting array. Return 0 if there is no such subarray. Exam.

qq_43661234的博客 236

如何在 SAP Server Side JavaScript 里消费 destination

在SAP云平台里打开SAP HANA Web-Based Development Workbench进行服务器端JavaScript的开发。 创建一个新的package: 创建一个新的application: 创建一个新的文件google-distance-api.xshttpdest用于维护destination相关信息: host = "maps.googlea...

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 622

[leetcode] 1493. Longest Subarray of 1‘s After Deleting One Element

Description Given a binary array nums, you should delete one element from it. Return the size of the longest non-empty subarray containing only 1’s in the resulting array. Return 0 if there is no such subarray. Example 1: Input: nums = [1,1,0,1] Output: 3

Learning from the mistakes 288

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

【LeetCode 热题 100】73. 矩阵置零|数组、矩阵、原地算法(Python)

【LeetCode 热题 100】【73. 矩阵置零】|数组、矩阵、原地算法(Python)

weixin_70673823的博客 313

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

LeetCode Hot 100 二分查找专题 34 / 33 / 153(Java)

专题主线:三道题共用同一副二分骨架,差别只在循环条件和收缩方向: 34.在排序数组中查找元素的第一个和最后一个位置:用 left <= right 练「边界二分」, 153.寻找旋转排序数组中的最小值:用 left < right + right = mid 练「下界模板」, 33.搜索旋转排序数组:是二者的组合应用。

2401_88612756的博客 560

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

leetcode-腐烂的橘子-双端队列记录坏橘子,取出后去感染新橘子

每分钟,腐烂的橘子 周围 4 个方向上相邻 的新鲜橘子都会腐烂。示例 1:[https://assets.leetcode.cn/aliyun-lc-upload/uploads/2019/02/16/oranges.png]输入:grid = [[2,1,1],[1,1,0],[0,1,1]]输出:4示例 2:输入:grid = [[2,1,1],[0,1,1],[1,0,1]]输出:-1解释:左下角的橘子(第 2 行, 第 0 列)永远不会腐烂,因为腐烂只会发生在 4 个方向上。每循环一次记为一分钟,

记录一点 247

LeetCode //C - 1326. Minimum Number of Taps to Open to Water a Garden

Summary: The problem involves finding the minimum number of taps needed to water a garden spanning from 0 to n on the x-axis. Each tap at position i can water a range centered at i with a given radius. The solution employs a greedy approach by first transf

Made in Code 194

LeetCode100 35.搜索插入位置

二分查找模板可高效求解插入位置。左闭右开区间下,循环终止时l即为插入下标:若target大于所有元素,l = nums.length;若在两数之间,l落在左侧。通过mid = l + (r - l) / 2避免溢出,nums[mid] < target时左移边界,否则右移,最终返回l,无需额外判断。

Shaoxingzong的博客 90

【算法刷题】LeetCode 力扣 Hot 100 刷题记录

力扣 Hot 100 刷题代码记录

2401_87820834的博客 215

LeetCode Hot 100 栈专题(20 / 155 / 394 / 739)(Java)

本专题四道题恰好覆盖栈的三类核心用法:括号匹配(延迟匹配)、辅助栈维护额外信息(最小值)、单调栈找下一个更大元素。把这三类打通,Hot 100 里的栈题基本可以通吃。 覆盖:20.有效的括号、155.最小栈、394.字符串解码、739.每日温度

2401_88612756的博客 327

LeetCode100 139.单词拆分

该解法使用动态规划判断字符串是否可被字典中的单词拆分。定义 dp[i] 表示前 i 个字符能否被成功拆分。遍历每个位置 i,尝试所有可能的分割点 j,若 dp[j] 为真且子串 s[j:i] 在字典中,则 dp[i] 设为真。一旦找到可行分割即跳出内层循环。最终返回 dp[n]。时间复杂度 O(n²),空间复杂度 O(n)。

Shaoxingzong的博客 181

LeetCode Hot 100 堆专题 215. 数组中的第 K 个最大元素 / 347. 前 K 个高频元素(Java)

本专题收录 Hot 100 中与「堆 / 优先队列」相关的两道题:215. 数组中的第 K 个最大元素、347. 前 K 个高频元素,每题按「题目分析与解题思路 → 常见解法(附代码)与讲解 → 知识点总结」三段组织。

2401_88612756的博客 245

【LeetCode 热题 100】1. 两数之和|数组、哈希表(Python)

【LeetCode 热题 100】【1. 两数之和】|数组、哈希表(Python)

weixin_70673823的博客 259

【leetcode】179.最大数js

本题通过自定义排序规则,将数字转为字符串后,比较拼接结果 a+b 与 b+a 的大小,决定顺序。若 a+b > b+a,则 a 排在 b 前。最终需特判全零情况(如 [0,0,0]),避免输出 '000'。利用 JS sort 的比较逻辑,简洁实现最大数字拼接。

2402_83244812的博客 199

LeetCode100 73.划分字母区间

本文介绍两种解决字符串分区问题的方法:一是通过记录每个字符最后一次出现位置,遍历时维护当前区间末尾,当当前位置等于该末尾时分割;二是通过记录每个字符的起始与结束位置,合并重叠区间后计算各段长度。两者均能正确划分字符串为最小不重叠分区,返回各分区长度。

Shaoxingzong的博客 175
上一篇: yolov8源码解读(part2: 检测,分割)
下一篇: leetcode 1218. Longest Arithmetic Subsequence of Given Difference(给定差值的最长算术子序列)
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址