Leetcode 第 385 场周赛题解

飞牛NAS+Docker打造私人IPTV直播源:手把手教你部署iptv-api 本文详细介绍了如何在飞牛NAS上通过Docker部署iptv-api,打造私人IPTV直播源。从SSH配置到Docker容器部署,手把手教你实现自动更新直播源、多终端支持的解决方案,适用于Kodi、PotPlayer等播放器,提升家庭娱乐体验。 阅读详情

Leetcode 第 385 场周赛题解

题目1:3042. 统计前后缀下标对 I

思路

暴力枚举下标为 i 和 j 的字符串 words[i] 和 words[j],当满足条件:

words[i] == words[j].substr(0, words[i].size()) && words[i] == words[j].substr(words[j].size() - words[i].size()) 时,

计数器 count++,最后返回 count。

代码

/*
 * @lc app=leetcode.cn id=3042 lang=cpp
 *
 * [3042] 统计前后缀下标对 I
 */

// @lc code=start
class Solution
{
public:
    int countPrefixSuffixPairs(vector<string> &words)
    {
        if (words.empty())
            return 0;

        int n = words.size(), count = 0;
        for (int i = 0; i < n - 1; i++)
            for (int j = i + 1; j < n; j++)
            {
                int len1 = words[i].size(), len2 = words[j].size();
                if (len1 <= len2)
                    if (words[i] == words[j].substr(0, len1) &&
                        words[i] == words[j].substr(len2 - len1))
                        count++;
            }
        return count;
    }
};
// @lc code=end

复杂度分析

时间复杂度:O(n2),其中 n 是数组 words 的元素个数。

空间复杂度:O(1)。

题目2:3043. 最长公共前缀的长度

思路

数字不好比较前缀,把它们转换成字符串再进行比较。

将数组 arr1 的元素的所有前缀插入到一个字符串集合 strSet 中,遍历数组 arr2 的元素 x,转换成字符串 s,取 s 的前缀在集合中搜索,若找到,更新最长公共前缀的长度。

最后返回最大值即可。

代码

/*
 * @lc app=leetcode.cn id=3043 lang=cpp
 *
 * [3043] 最长公共前缀的长度
 */

// @lc code=start
class Solution
{
public:
    int longestCommonPrefix(vector<int> &arr1, vector<int> &arr2)
    {
        set<string> strSet;
        for (int &x : arr1)
        {
            string s = to_string(x);
            for (int i = 1; i <= s.length(); i++)
                strSet.insert(s.substr(0, i));
        }

        int ans = 0;
        for (int &x : arr2)
        {
            string s = to_string(x);
            for (int len = 1; len <= s.length(); len++)
            {
                string temp = s.substr(0, len);
                if (strSet.count(temp))
                    ans = max(ans, len);
            }
        }

        return ans;
    }
};
// @lc code=end

复杂度分析

时间复杂度:O((n+m)log2U),,其中 n 为数组 arr1 的长度,m 为数组 arr2 的长度,U 为数组元素的最大值。

空间复杂度:O(nlog2U),,其中 n 为数组 arr1 的长度,U 为数组元素的最大值。

题目3:3044. 出现频率最高的质数

思路

对于每个单元格,枚举八个方向,生成数字,用一个哈希表统计其中质数个数。

最后返回出现次数最多的质数,如果有多个这样的质数,返回最大的那个。

代码

/*
 * @lc app=leetcode.cn id=3044 lang=cpp
 *
 * [3044] 出现频率最高的质数
 */

// @lc code=start
class Solution
{
private:
    const int dx[8] = {-1, -1, -1, 1, 1, 1, 0, 0};
    const int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1};

public:
    int mostFrequentPrime(vector<vector<int>> &mat)
    {
        if (mat.empty())
            return 0;

        int m = mat.size(), n = m ? mat[0].size() : 0;

        unordered_map<int, int> cnt;
        for (int i = 0; i < m; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < 8; k++)
                {
                    int r = i + dx[k], c = j + dy[k], v = mat[i][j];
                    // 只统计大于 10 的质数
                    // if (isPrime(v))
                    //     cnt[v]++;
                    while (r >= 0 && r < m && c >= 0 && c < n)
                    {
                        v = 10 * v + mat[r][c];
                        if (isPrime(v))
                            cnt[v]++;
                        r += dx[k];
                        c += dy[k];
                    }
                }

        int ans = -1, maxCount = 0;
        for (auto &[num, count] : cnt)
        {
            if (count > maxCount)
            {
                ans = num;
                maxCount = count;
            }
            else if (count == maxCount)
                ans = max(ans, num);
        }
        return ans;
    }
    // 辅函数 - 判断数字 n 是否是质数
    bool isPrime(int n)
    {
        for (int i = 2; i * i <= n; i++)
        {
            if (n % i == 0)
                return false;
        }
        return true;
    }
};
// @lc code=end

复杂度分析

时间复杂度:O(mnk*10k/2),其中 m 和 n 分别为 mat 的行数和列数,k=max(m,n)。总共有 O(mnk) 个数,判断质数需要 O(10k/2) 的时间。

空间复杂度:O(mnk),其中 m 和 n 分别为 mat 的行数和列数,k=max(m,n)。

题目4:3045. 统计前后缀下标对 II

思路

在这里插入图片描述

将这个列表哈希化:idx = (s[i] - ‘a’) * 26 + (s[j] - ‘a’)。

枚举 t=words[j],怎么统计有多少个 s=words[i] 是 t 的前缀?

这可以用字典树解决,在遍历 words 的同时,维护每个字符串的出现次数。当我们遍历 t 时,同时遍历字典树上的对应节点,并把 t 插入字典树。

代码

/*
 * @lc app=leetcode.cn id=3045 lang=cpp
 *
 * [3045] 统计前后缀下标对 II
 */

// @lc code=start

// 字典树

class Solution
{
public:
    struct Trie
    {
        unordered_map<int, Trie *> childs;
        int cnt = 0;
    };
    Trie *trie = new Trie();
    void add(const string &s)
    {
        Trie *cur = trie;
        int n = s.size();
        for (int i = 0, j = n - 1; i < n; ++i, --j)
        {
            int idx = (s[i] - 'a') * 26 + (s[j] - 'a');
            if (!cur->childs.count(idx))
            {
                cur->childs[idx] = new Trie();
            }
            cur = cur->childs[idx];
            cur->cnt += 1;
        }
    }
    int query(const string &s)
    {
        Trie *cur = trie;
        int n = s.size();
        for (int i = 0, j = n - 1; i < n; ++i, --j)
        {
            int idx = (s[i] - 'a') * 26 + (s[j] - 'a');
            if (!cur->childs.count(idx))
                return 0;
            cur = cur->childs[idx];
        }
        return cur->cnt;
    }
    long long countPrefixSuffixPairs(vector<string> &words)
    {
        int n = words.size();
        long long ans = 0;
        for (int i = n - 1; i >= 0; --i)
        {
            ans += query(words[i]);
            add(words[i]);
        }
        return ans;
    }
};
// @lc code=end

复杂度分析

时间复杂度:O(L),其中 L 为所有 words[i] 的长度之和。

空间复杂度:O(L),其中 L 为所有 words[i] 的长度之和。

SpringBoot 教程:SpringBoot多种方式实现静态Html页面跳转 本教程介绍了 Spring Boot 中实现静态 Html 页面跳转的常用方法,包括重定向跳转、直接返回 ModelAndView 对象以及使用 Thymeleaf 模板引擎。如果你的项目中使用了 Thymeleaf 模板引擎,那么可以利用它来实现静态页面的跳转。对于静态的 Html 页面,我们可以使用多种方式来实现跳转功能。重定向是一种常见的页面跳转方式,它通过发送 HTTP 重定向响应头来告知浏览器跳转到指定的页面。在 Spring Boot 中,我们可以将视图名称设置为静态页面的路径。 阅读详情

相关推荐

yolov8的Detect层详解(输出维度改动)

对于部署端需要拿到onnx的output进行后处理,但是基于anchor_free的yolov8输出是1*(4+cls)*8400,不是我们常见的ncwh格式,所以对Detect层进行了学习,分享一下体会。

yjcccccc的博客 2万+

LeetCode 第385场周赛个人题解

怎么又是字符串问题

EQUINOX1的博客 1066

《点亮创新灯塔!AI应用架构师与中小学初等教育AI智能体,共筑智能化教育辅助创新灯塔》

中小学AI智能体,是基于AI技术,能感知教育场景、理解教育规律、辅助教师教学和学生学习的智能系统。做老师“做不了”的事:比如5分钟批改45本作业,精准统计每个学生的易错点;做老师“做不好”的事:比如根据学生的学习风格(视觉/听觉/动觉)推荐个性化内容;绝不做老师“该做的事”:比如情感交流、价值观引导、创意教学设计——这些“人的温度”,AI永远无法替代。我是林宇,资深AI应用架构师,专注教育AI领域8年,参与过10多个中小学AI智能体项目,曾为北京、上海、深圳等城市的100多所学校提供AI教育解决方案。

Java大师兄的博客 438

[Leetcode] 反转链表

反转链表的三道题

皮卡丘在充电 231

ESP32水墨屏日历实战:低功耗自动更新与HTTPS数据解析

本文详细介绍了ESP32水墨屏日历项目的开发实践,重点讲解了低功耗自动更新与HTTPS数据解析的实现方法。通过ESP32的自动休眠功能和水墨屏的零功耗特性,结合HTTPS请求安全获取网络数据,实现了高效节能的桌面日历应用。项目代码开源,适合物联网开发者参考。

xx56789的博客 783

永磁同步电机控制笔记:foc控制原理通俗讲义

引言 到此为止,永磁同步电机控制相关文章已经写了7篇,其中simulink仿真系列文章5篇,控制笔记系列文章2篇,恍惚间感觉少了一篇概论,在此插入一篇,也算是对入坑电机控制一年半来的知识梳理。 文章目录引言一、同步电机是怎么转起来的二、什么样的旋转磁场效率最高三、怎么精准控制旋转磁场的方向四、怎样调节dq轴电流 一、同步电机是怎么转起来的 永磁同步电机结构如下: 外围是定子绕组,中间为永磁体,设...

搞电机的博客 2万+

LeetCode //C - 1325. Delete Leaves With a Given Value

This problem involves removing all leaf nodes from a binary tree that have a given target value, including cases where parent nodes become new leaves with the target value after deletion. The solution uses a postorder traversal approach (left-right-root) t

Made in Code 393

【二 Deepseek+Coze案例】【 2.2 Coze + Deepseek 实现小红书爆款笔记:打造专属Agent智能体】

摘要 本文介绍了如何利用Coze平台和Deepseek模型构建自动化Agent智能体,用于生成和优化小红书爆款笔记。文章首先分析了爆款笔记的核心特征,包括精准定位、吸引标题、实用内容、精美排版和热门标签。随后提出Agent智能体的功能需求,涵盖热点追踪、内容生成与优化、数据分析及自动发布等模块。在技术实现上,详细阐述了从环境配置、数据采集到内容生成与优化的全流程,并提供了Python代码示例,展示如何调用Coze函数获取热点数据及竞品笔记。该方案通过智能化的内容创作与运营策略,帮助用户高效打造高曝光的小红书

商务合作|问题讨论|交流学习 请联系作者微信,加微信请务必注明来意,博客主页有联系方式 2335

LeetCode100 136.只出现一次的数字

利用异或运算性质:相同数异或为0,任何数与0异或为自身,且异或满足交换律和结合律。数组中成对数字异或后抵消为0,仅剩唯一出现一次的数。通过遍历数组异或所有元素,可在线性时间复杂度O(n)和常数空间复杂度O(1)内求解。

Shaoxingzong的博客 223

RK3568_Android15适配以太网网卡gmac+国产phy芯片YT8531

本文介绍了在Android15 SDK上适配正点原子ATK-DLRK3568开发板网卡的过程。开发板采用GMAC接口搭配YT8531C PHY芯片,包含两个千兆网口。主要内容包括:硬件原理图确认、网络链路连接方式、内核DTS配置(包括GMAC0和GMAC1的参数设置)、PHY驱动适配(基于motorcomm.c驱动文件)、PHY寄存器读写调试方法以及MAC地址设置方式。文章还分析了常见问题,如网卡注册后无法ping通网络的故障现象。通过详细的硬件确认和软件配置,实现了双网卡在Android系统上的完整适配。

Android/Linux驱动开发传帮带学习,让驱动入门门槛更低! 2047

ZYNQ 7020 之 FPGA知识点重塑笔记一——串口通信

通信方式一般分为串行通信和并行通信。并行通信是指多比特数据同时通过并行线进行传送。这种传输方式通信线多、成本高,故不宜进行远距离通信,通常传输距离小于 30 米。串行通信是指数据在一条数据线上,一比特接一比特地按顺序传送的方式。这种运输方式通常节省传输线,大大降低使用成本,但数据传送速度慢。综上可知,串行通信主要应用于长距离、低速率的通信场合。本次实验我们主要讲解下串行通信。串行通信一般有2种通信方式:同步串行通信和异步串行通信。同步串行通信。

m0_51430584的博客 3103

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

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

2401_88612756的博客 327

【异常】Milvus 向量数据库字段缺失错误分析与解决 MilvusVectorStoreServiceV2 - Failed to insert batch [0-1]: The field:

本文分析了Milvus向量数据库插入操作中出现的字段缺失错误。错误显示age_mode字段未提供,导致批量插入失败。根本原因是Milvus Schema要求所有定义字段必须存在,但代码中对部分字段采用条件添加方式。解决方案是将条件添加改为始终添加,为可能为null的字段提供空字符串默认值。文章总结了Schema约束、防御性编程等经验,并建议通过Schema变更检查、单元测试覆盖和数据校验层等预防措施避免类似问题。该问题影响product、mac、source等多个字段,修改后确保了数据插入的可靠性。

奶爸的编程之路,也就一周冷个三天 427

LeetCode100 139.单词拆分

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

Shaoxingzong的博客 181

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

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

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

2401_88612756的博客 241

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

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

LeetCode 3411.最长乘积等价子数组:二重循环“暴力”计算

LeetCode 3411.最长乘积等价子数组:二重循环“暴力”计算 给你一个由 正整数 组成的数组 nums。 如果一个数组 arr 满足 prod(arr) == lcm(arr) * gcd(arr),则称其为 乘积等价数组 ,其中: prod(arr) 表示 arr 中所有元素的乘积。 gcd(arr) 表示 arr 中所有元素的最大公因数 (GCD)。 lcm(arr) 表示 arr 中所有元素的最小公倍数 (LCM)。 返回数组 nums 的 最长 乘积等价 子数组 的长度。

<font color="Pink">Tisfy的博客</font> 228

深度学习工具包 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")

LeetCode100 73.划分字母区间

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

Shaoxingzong的博客 137

LeetCode 207 课程表:用三态 DFS 判断有向图的环

用先修关系画图,讲清 DFS 的三种状态、两条路径汇合时为何不算环,以及怎样避免漏查独立分量。附 C++17 实现和 6 个本地验证用例。

wu77777777wu的博客 172

LeetCode Hop100 -- (160.相交链表)思路与总结

本文详解链表相交问题的三种解法:暴力遍历(O(mn))、哈希集合优化(O(m+n),O(m)空间),以及双指针巧妙解法(O(m+n),O(1)空间)。核心思想是通过让两指针分别走完自身链表后转向另一条,使它们在相遇点同步,从而找到交点。适用于求两条链表的公共节点,体现从暴力到优化的思维递进。

NGEFF的博客 200

LeetCode 33:搜索旋转排序数组——从二分查找到旋转数组的区间判定

本文详解LeetCode第33题“搜索旋转排序数组”的解法。核心思想是利用旋转数组中至少一半区间有序的特性,结合二分查找,在每次迭代中判断左半或右半部分是否有序,并据此确定目标值可能存在的区间,从而高效定位目标。通过合理更新边界,实现O(log n)时间复杂度。关键点包括:使用left <= right确保单元素处理、mid = left + (right - left)/2防溢出、以及根据有序区间判断目标范围。适用于无重复元素的旋转数组,若存在重复则需额外处理,可能导致最坏O(n)复杂度。

yu____yuan的博客 173

LeetCode Hot 100 -- (206.反转链表) 思路与总结

这题的思路是两层推上来的:首先是既然不能倒着走,就把节点全存进 List,再倒着重新连然后是发现处理每个节点其实只要 prev、next 两个信息,用三个指针滚着走就行如果题目里出现单链表、要反转、要改变节点之间的指向关系,先想三指针:存下一个、掉头、两个指针一起前进,大概思路就是这样了。

NGEFF的博客 184

LeetCode //C - 1324. Print Words Vertically

This solution takes a string s and prints its words vertically in the same order they appear. The key steps involve: Counting and storing each word's start position and length. Determining the maximum word length, which defines the number of output strings

Made in Code 507

LeetCode //C - 1320. Minimum Distance to Type a Word Using Two Fingers

This problem involves finding the minimum total distance to type a given word using two fingers on a keyboard layout where letters are arranged in a grid. The solution uses dynamic programming to track the positions of the two fingers after each keystroke,

Made in Code 540

LeetCode100 287.寻找重复数

利用Floyd判圈算法找环入口:快慢指针从起点出发,慢指针走一步,快指针走两步,直至相遇;随后将慢指针重置到起点,两者同速前进,再次相遇点即为环入口——对应数组中的重复数字。核心原理:相遇点到环入口的距离等于起点到环入口的距离。时间复杂度O(n),空间复杂度O(1)。

Shaoxingzong的博客 236

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 192
上一篇: Leetcode3045. 统计前后缀下标对 II
下一篇: 最简单的基于 FFmpeg 的视音频复用器
UestcXiye
博客等级 码龄8年 9047粉丝 1306原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

打赏作者

UestcXiye

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

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

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

打赏作者

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

抵扣说明:

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

余额充值
⌂ 换网址