leetcode(91-95)

Leetcode刷题(91~95) 算法是码农的基本功,也是各个大厂必考察的重点,让我们一起坚持写题吧。 遇事不决,可问春风,春风不语,即是本心。 我们在我们能力范围内,做好我们该做的事,然后相信一切都事最好的安排就可以啦,慢慢来,会很快,向前走,别回头。 阅读详情

91. 解码方法

一条包含字母 A-Z 的消息通过以下方式进行了编码:

'A' -> 1
'B' -> 2
...
'Z' -> 26

给定一个只包含数字的非空字符串,请计算解码方法的总数。

示例 1:

输入: "12"
输出: 2
解释: 它可以解码为 "AB"(1 2)或者 "L"(12)。

示例 2:

输入: "226"
输出: 3
解释: 它可以解码为 "BZ" (2 26), "VF" (22 6), 或者 "BBF" (2 2 6) 。
class Solution {
public:
	int numDecodings(string s) {
		if (s.empty())return 0;
		vector<int>v(s.size() + 1, 0);
		v[0] = 1;
		v[1] = (s[0] == '0') ? 0 : 1;
		for (int i = 2; i <= s.size(); ++i) {
			auto t1 = stoi(s.substr(i - 1, 1));
			if (t1>0 && t1<10)v[i] += v[i - 1];
			auto t2 = stoi(s.substr(i - 2, 2));
			if (t2<27 && t2>9)v[i] += v[i - 2];
		}
		return v.back();
	}
};

92. 反转链表 II

反转从位置 m 到 n 的链表。请使用一趟扫描完成反转。

说明:
1 ≤ m ≤ n ≤ 链表长度。

示例:

输入: 1->2->3->4->5->NULL, m = 2, n = 4
输出: 1->4->3->2->5->NULL
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseBetween(ListNode* head, int m, int n) {
        if(head==NULL || head->next==NULL || m>=n || m<0 || n<0) return head;
        ListNode* h = new ListNode(-1);
        h->next = head;
        ListNode* pre = h;
        ListNode* cur = head;
        int i=1;
        for(; i<m && cur != NULL; ++i){
            pre = cur;
            cur = cur->next;
        }
        ListNode* t1 = pre;
        ListNode* t2 = cur;
        for(; i<=n && cur != NULL; ++i){
            ListNode* tmp = cur->next;
            cur->next = pre;
            pre = cur;
            cur = tmp;
        }
        t1->next = pre;
        t2->next = cur;
        return h->next;
    }
};

93. 复原IP地址

给定一个只包含数字的字符串,复原它并返回所有可能的 IP 地址格式。

示例:

输入: "25525511135"
输出: ["255.255.11.135", "255.255.111.35"]
class Solution {
public:
    vector<string> restoreIpAddresses(string s) {
        vector<string> res;
        if(!s.empty() && s.size()<4 && s.size()>12) return res;
        restoreIpAdd(s, 4, 0, string(""), res);
        return res;
    }
    void restoreIpAdd(string s, int n, int index, string ip, vector<string>& res){
        if(n==0){
            if(index == s.size()) res.push_back(ip);
            return;
        }
        for(int i=index+1; i <= s.size(); i++){
            string tmpS = string(s.begin()+index, s.begin()+i);
            if(isNum(tmpS)){
                if(ip.empty()) restoreIpAdd(s, n-1, i, tmpS, res);
                else{
                    tmpS = ip+"."+tmpS;
                    restoreIpAdd(s, n-1, i, tmpS, res);
                }
            } else break;
        }
    }
    bool isNum(string num){
        if (0 <= stoi(num) and stoi(num) <= 255 and to_string(stoi(num)) == num){
            return true;
        }
        return false;
    }
};

94. 二叉树的中序遍历

给定一个二叉树,返回它的中序 遍历。

示例:

输入: [1,null,2,3]
   1
    \
     2
    /
   3

输出: [1,3,2]

 

95. 不同的二叉搜索树 II

给定一个整数 n,生成所有由 1 ... n 为节点所组成的二叉搜索树。

示例:

输入: 3
输出:
[
  [1,null,3,2],
  [3,2,null,1],
  [3,1,null,null,2],
  [2,1,3],
  [1,null,2,null,3]
]
解释:
以上的输出对应以下 5 种不同结构的二叉搜索树:

   1         3     3      2      1
    \       /     /      / \      \
     3     2     1      1   3      2
    /     /       \                 \
   2     1         2                 3
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    vector<int> inorderTraversal(TreeNode* root) {
        vector<int> res;
        if(root == NULL) return res;
        stack<TreeNode*> st;
        while(!st.empty() || root!=NULL){
            if(root!=NULL){
                st.push(root);
                root=root->left;
            } else {
                root=st.top();
                st.pop();
                res.push_back(root->val);
                root=root->right;
            }
        }
        return res;
    }
};

95. 不同的二叉搜索树 II

给定一个整数 n,生成所有由 1 ... n 为节点所组成的二叉搜索树。

示例:

输入: 3
输出:
[
  [1,null,3,2],
  [3,2,null,1],
  [3,1,null,null,2],
  [2,1,3],
  [1,null,2,null,3]
]
解释:
以上的输出对应以下 5 种不同结构的二叉搜索树:

   1         3     3      2      1
    \       /     /      / \      \
     3     2     1      1   3      2
    /     /       \                 \
   2     1         2                 3
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    vector<TreeNode*> generateTrees(int n) {
        if(n==0) return vector<TreeNode*>();
        return fun(1,n);
    }
    vector<TreeNode*> fun(int l, int r){
        vector<TreeNode*> res;
        if(l>r) res.push_back(NULL);
        for(int k=l; k<=r; k++){
            vector<TreeNode*> left=fun(l,k-1);
            vector<TreeNode*> right=fun(k+1,r);            
            for(int i=0; i<left.size(); i++) {
                for(int j=0; j<right.size(); j++){
                    TreeNode* tmp = new TreeNode(k);
                    tmp->left=left[i];
                    tmp->right=right[j];
                    res.push_back(tmp);
                }
            }
        }
        return res;
    }
};

(以上题目均摘自leetcode)

LeetCode刷题模版:91 - 100 Hello!ଘ(੭ˊᵕˋ)੭昵称:海轰标签:程序猿|C++选手|学生简介:因C语言结识编程,随后转入计算机专业,获得过国家奖学金,有幸在竞赛中拿过一些国奖、省奖…已保研学习经验:扎实基础 + 多做笔记 + 多敲代码 + 多思考 + 学好英语!唯有努力💪本文仅记录自己感兴趣的内容文章仅作为个人学习笔记记录,记录从0到1的一个过程希望对您有一点点帮助,如有错误欢迎小伙伴指正。 阅读详情

相关推荐

项目经理面试 5 大高频题 + 实战回答模板,帮你稳拿 offer

项目经理面试5大高频问题及应答技巧 摘要:本文总结了项目经理岗位常见的5个面试问题及回答策略,帮助求职者更有针对性地准备面试。核心问题包括:1)描述负责过的典型项目;2)常用项目管理工具;3)项目遇到的挑战及解决方案;4)风险管理方法;5)项目成功标准。每个问题都从面试官考察重点、回答技巧、实战案例三个维度进行分析,强调要用STAR法则(情境-任务-行动-结果)结构化表达,突出解决问题的能力而非简单罗列经历。特别提醒要量化项目成果(如提前2周上线、节省8%预算等),并注意展示商业思维和团队协作能力。

逸尘谈PM 2105

【LeetCode Solutions】LeetCode 91 ~ 95 题解

【LeetCode Solutions】LeetCode 91 ~ 95 题解

一只快乐的小蒟蒻~ 954

手把手调试Altera FPGA远程升级:从ASMI扇区擦除到Remote Update IP配置的避坑实录

本文详细解析了Altera FPGA远程升级的全流程,重点介绍了Cyclone IV系列FPGA的ASMI扇区擦除和Remote Update IP配置的实战技巧。通过双镜像架构设计、ASMI IP核优化配置及Remote Update IP的隐藏参数设置,帮助开发者避免常见陷阱,提升远程升级的可靠性和效率。

weixin_30872499的博客 447

LeetCode 91~95

前言 本文隶属于专栏《LeetCode 刷题汇总》,该专栏为笔者原创,引用请注明来源,不足和错误之处请在评论区帮忙指出,谢谢! 本专栏目录结构请见LeetCode 刷题汇总 正文 幕布 幕布链接 解码方法 官方解法 动态规划 反转链表 II Simple Java solution with clear explanation 双指针+哨兵 复原 IP 地址 DFS,特殊考虑 0 Very simple DFS solution 代码实现 4层循环,parse and append WHO CAN

Shockang的博客 6347

在WinXP操作系统上安装Tornado2.2详细教程

使用VxWorks的人都想在自己的电脑中装VxWorks的编译器Tornado,然而Win10操作系统对于Tornado并不友好,根本装不成功。而对于Win7操作系统,之前在实验室一台Win7上装Tornado成功过,并且一直在上面进行vx开发,但是过一段时间在其他Win7上装Tornado时又不能成功,由此说明Tornado对于Win7操作系统对Tornado的兼容也不是很好,所以想要长久使用T...

weixin_43822311的博客 4481

14、网络切片技术:原理、应用与挑战

本文详细探讨了网络切片技术的原理、应用场景及其在5G网络中的重要性。网络切片作为一种关键的网络架构技术,能够在同一物理网络上创建多个独立的逻辑网络,以满足不同应用对安全性、可靠性和性能的多样化需求。文章深入分析了网络切片在5G、SDN/NFV等技术背景下的发展与挑战,并探讨了其在制造业、交通运输、零售等多个行业的实际应用。此外,还介绍了网络切片的部署流程、未来发展趋势以及相关技术难点,为读者全面了解网络切片技术提供了有价值的参考。

palm99的专栏 254

【JavaScript】LeetCode:91-95

【代码】【JavaScript】LeetCode:91-95。

weixin_45980065的博客 847

LVS 负载均衡面试题及参考答案

什么是 LVS 负载均衡?它的主要作用是什么? LVS(Linux Virtual Server)是一个基于 Linux 内核的开源负载均衡项目。它通过将请求流量按照一定的算法分发到后端的多个真实服务器(Real Server)上,从而实现负载均衡的功能。 从原理上来说,LVS 工作在网络层和传输层之间。当客户端发起请求时,请求首先到达 LVS 服务器,LVS 会根据预先设定的规则和算法,比如轮询(Round - Robin)、加权轮询(Weighted Round - Robin)、最少连

大模型大数据攻城狮的专栏 1469

力扣爆刷第101天之hot100五连刷91-95

思路:求最长公共子序列,如text1 = “abcde”, text2 = “ace” ,定义dp[i][j]表示区间[0, i] 和区间[0, j]中以text1[i]和text2[j]字符为结尾,如果二者相等则 dp[i+1][j+1] = dp[i][j] + 1;,如果不等,可以考虑从左边,上边,左上角。思路:求不同路径,任意一个位置都可以从它的上方和左方推出,也就是dp[i][j] = dp[i][j-1] + dp[i-1][j],压缩数组为dp[j] = dp[j] + dp[j-1];

qq_43511039的博客 831

A2A 协议详解:Agent Card 的设计与实现

Agent Card 是 Agent2Agent (A2A) 协议中实现智能体发现与互操作性的核心组件。本文将深入剖析 Agent Card 的设计理念、关键字段及其在智能体生态系统中的作用。我们将通过详细的 JSON Schema 解析和 Python SDK 示例,帮助您理解如何精确地定义和发布智能体能力,为构建可发现、可协作的 AI 智能体奠定基础。当您使用a2a.Agent类初始化一个智能体时,SDK 会根据您提供的参数(nameversion等)自动构建内部的 Agent Card 表示。

加入“Super Entity”,与全能开发团队共探AI智能体与数字人项目,开启前沿技术之旅。 1476

FLACS-CFD 气云爆炸模拟全流程工况构建指南:从泄漏到爆炸

摘要: 本文详细介绍了使用FLACS-CFD模拟气云爆炸的全流程构建方法,重点解决泄漏模拟到爆炸模拟的气云文件传递问题。核心步骤包括: 项目规划:明确泄漏源(甲烷管道腐蚀泄漏)和爆炸场景,建立标准目录结构; 网格设计:泄漏与爆炸模拟需采用兼容的网格,爆炸域应为泄漏域的子区域且网格划分一致; 泄漏模拟配置:通过.inp文件定义几何、网格、风场、燃料及泄漏源参数,确保输出爆炸所需的气云文件(*.uni/*.fla); 关键设置:统一燃料名称、时间点匹配、路径正确性,避免版本兼容性问题。

huanghm88的专栏 762

力扣爆刷第121天之CodeTop100五连刷91-95

题目链接:https://leetcode.cn/problems/remove-duplicates-from-sorted-list/description/思路:利用栈来做,用一个符号位记录运算符,当再次遇到运算符时,就把之前记录的数和之前的运算符相运算,入栈,更新运算符,最后注意边界条件,别漏掉最后一个数的计算。下面用动态规划来做,定义dp[i]表示以s[i]为结尾的字符串可以被表示出来,故,只要当前这一段可以被表示出来,那么当前位置的状态取决于上一段的结尾。全局变量计数,统计即可。

qq_43511039的博客 402

深度学习工具包 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 hot/91-95

目录461-汉明距离494-目标和538-把二叉搜索树转换为累加树543-二叉树的直径560. 和为K的子数组 461-汉明距离 两个整数之间的 汉明距离 指的是这两个数字对应二进制位不同的位置的数目。 给你两个整数 x 和 y,计算并返回它们之间的汉明距离。 示例 1: 输入:x = 1, y = 4 输出:2 解释: 1 (0 0 0 1) 4 (0 1 0 0)           &nbsp

fan__lee的博客 182

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

力扣hot100题解(python版91-95题)

一个机器人位于一个m x n网格的左上角 (起始点在下图中标记为 “Start” )。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish” )。问总共有多少条不同的路径?2 * 109。

小橘子的博客 1137

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

每日5题Day19 - LeetCode 91 - 95

【代码】每日5题Day19 - LeetCode 91 - 95。

alimamaalala的博客 656

leetcode题解python版:91-95

91、解码方法 一条包含字母 A-Z 的消息通过以下方式进行了编码: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 给定一个只包含数字的非空字符串,请计算解码方法的总数 解:这道题用递归显然是没有问题的。这里要注意的是0,单独一个0显然无法解码,0只能变为10,20来解码,否则s是无法解码的。 class Solution: def numDecodings(self, s: str) -> int: n=len(s) if

baidu_41689104的博客 363

【leetcode82-91动态规划,91-95多维动态规划】

动态规划【82-91】 多维动态规划【91-95】

qq_46277517的博客 544

Python小白 Leetcode刷题历程 No.91-No.95 解码方法、反转链表Ⅱ、复原IP地址、二叉树的中序遍历、不同的二叉搜索树Ⅱ (有题干 有代码 有思路心得)

文章目录Python小白 Leetcode刷题历程 No.91-No.95 解码方法、反转链表Ⅱ、复原IP地址、二叉树的中序遍历、不同的二叉搜索树Ⅱ写在前面:No.91.解码方法No.92.反转链表ⅡNo.93.复原IP地址No.94.二叉树的中序遍历No.95.不同的二叉搜索树Ⅱ Python小白 Leetcode刷题历程 No.91-No.95 解码方法、反转链表Ⅱ、复...

LanXiu_的博客 648

面试笔试杂项积累-leetcode 91-95

91.91-Decode Ways-Difficulty: Medium A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message conta

wolf96的专栏 922

力扣爆刷第165天之TOP100五连刷91-95(岛屿DFS、打家劫舍、堆排)

思路:本题让求最大子数组的乘积,但是数组元素有正有负,这样就有可能出现正数乘着乘着变成负数,负数乘着乘着变成正数的问题,所以为了防止这样的两极问题的出现,可以专门 维护两个数组,一个是最大数值的数组,一个是最小数组的数组,这样对于每一个位置来说既可以只使用当前元素,也可以与前一个位置的最大乘积或者最小乘积相乘,以此进行比较。思路:排列算法有很多,一般掌握快排,堆排,归并。题目链接:https://leetcode.cn/problems/max-area-of-island/description/

qq_43511039的博客 459

day 3 91-95

题91题92题93题94题95翻译单词。

qq_42775632的博客 22

LeetCode 27.移除元素算法代码分享

    分享一道 LeetCode第27题. 移动元素算法的代码,此代码的执行时间为8ms,超过 95.95% 的用户;内存 8.4MB,超过 96.91% 的用户。 题目如下: 给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度。 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。 元素的顺序可以改...

weixin_42795141的博客 206

【leetcode】dp---中等(1)64. 最小路径和_dp迷宫(2)91. 解码方法_不定长子串(3)**95. 不同的二叉搜索树 II_dfs返回答案(4)**96. 不同的二叉搜索树_dp

64、给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。 说明:每次只能向下或者向右移动一步。 示例: 输入: [ [1,3,1], [1,5,1], [4,2,1]] 输出: 7 解释: 因为路径 1→3→1→1→1 的总和最小。 dp[i][j]=min(dp[i-1][j],dp[i][j-1])+grid[i][j] // dp[i][j]:到(i,j)最短路劲和 // 状态转移:1)左走一步,2)上走一步 //...

LanXinYue98的博客 230

一天一道LeetCode(91-120)

一天一道LeetCode(91-119) 文章目录一天一道LeetCode(91-119)91.解码方法92.反转链表 II93.复原IP地址95.不同的二叉搜索树 II96.不同的二叉搜索树97.交错字符串98.验证二叉搜索树99.回复二叉搜索树(未解决)100.相同的树101.对称二叉树102.二叉树的层序遍历103.二叉树的锯齿形层次遍历104.二叉树的最大深度105.从前序与中序遍历序列构造二叉树106.从中序与后序遍历序列构造二叉树107.二叉树的层次遍历108.将有序数组转换为二叉搜索树109.

summer_bugs的博客 541

Leetcode刷题记录91-100,python语言

【代码】Leetcode刷题记录91-100,python语言。

yuyu12prince的博客 415
上一篇: 机器学习---Apriori
下一篇: leetcode(96-100)
小小螺丝刀
博客等级 码龄10年 41粉丝 45原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值