leetcode 726. Number of Atoms 化学式展开 + 统计化学式的元素的数量

【复现论文】Looking here or there? Gaze Following in 360-Degree Images 论文:Looking here or there? 阅读详情

Given a chemical formula (given as a string), return the count of each atom.

An atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.

1 or more digits representing the count of that element may follow if the count is greater than 1. If the count is 1, no digits will follow. For example, H2O and H2O2 are possible, but H1O2 is impossible.

Two formulas concatenated together produce another formula. For example, H2O2He3Mg4 is also a formula.

A formula placed in parentheses, and a count (optionally added) is also a formula. For example, (H2O2) and (H2O2)3 are formulas.

Given a formula, output the count of all elements as a string in the following form: the first name (in sorted order), followed by its count (if that count is more than 1), followed by the second name (in sorted order), followed by its count (if that count is more than 1), and so on.

Example 1:
Input:
formula = “H2O”
Output: “H2O”
Explanation:
The count of elements are {‘H’: 2, ‘O’: 1}.
Example 2:
Input:
formula = “Mg(OH)2”
Output: “H2MgO2”
Explanation:
The count of elements are {‘H’: 2, ‘Mg’: 1, ‘O’: 2}.
Example 3:
Input:
formula = “K4(ON(SO3)2)2”
Output: “K4N2O14S4”
Explanation:
The count of elements are {‘K’: 4, ‘N’: 2, ‘O’: 14, ‘S’: 4}.
Note:

All atom names consist of lowercase letters, except for the first character which is uppercase.
The length of formula will be in the range [1, 1000].
formula will only consist of letters, digits, and round parentheses, and is a valid formula as defined in the problem.

就是直接解析字符串,然后获取元素的数量

其实我觉得直接按照括号匹配做展开也行,然后遍历统计元素也可以

代码如下:

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <climits>
#include <algorithm>
#include <sstream>
#include <functional>
#include <bitset>
#include <numeric>
#include <cmath>
#include <regex>

using namespace std;



class Solution 
{
public:
    string countOfAtoms(string formula) 
    {
        int n = formula.size();
        map<string, int> stats;
        reverse(formula.begin(), formula.end());
        compute(formula, stats);
        string result;

        for (auto& kv : stats) 
        {
            result += kv.first;
            if (kv.second > 1)
                result += std::to_string(kv.second);
        }
        return result;
    }

     // K4(ON(SO3)2)2
    void compute(string& formula, std::map<string, int>& stats)
    {
        int n = formula.size();

        std::stack<int> stk; // factor
        stk.push(1);

        string elem; // chemical element, e.g., C, N, O, Na, Mg, Al, etc.
        int factor = 1; // number of this element, default to 1 if not otherwise specified

        for (int i = 0; i < n; ++i) 
        {
            auto& c = formula[i];
            if (isdigit(c)) 
            { // E.g., original 312 was reverse to 213.
                int val = 0, expo = 1;
                do 
                {
                    val += (c - '0') * expo;
                    ++i; 
                    expo *= 10;
                } while (isdigit(c = formula[i]));
                factor = val; // explicit number of this element
                i -= 1;
            }
            else if (c == ')')
            {
                stk.push(factor * stk.top());
                factor = 1; //            Al(OH)3
            }
            else if (c >= 'A' && c <= 'Z') 
            {
                elem += c;
                std::reverse(elem.begin(), elem.end());
                stats[elem] += factor * stk.top();
                factor = 1;
                elem.clear();
            }
            else if (c >= 'a' && c <= 'z')
            {
                elem += c;
            }
            else 
            {    // (c == '(') {  
                stk.pop();  // Ca(OH)2
            }
        }
    }
};
STM32 SPI驱动TFT LCD实战:时序配置与硬件协同 SPI(串行外设接口)是一种高速、全双工、同步串行通信协议,广泛应用于微控制器与显示模组等外设的数据交互。其核心依赖时钟极性(CPOL)与时钟相位(CPHA)组合定义的四种工作模式,直接影响数据采样可靠性;而片选(NSS)与MOSI/SCLK等信号的硬件映射,则决定了多设备共总线下的通信稳定性。在TFT LCD驱动场景中,SPI凭借低开销、高吞吐优势成为主流选择,尤其适配ST7789、ILI9341等集成显示控制器的模块。本文聚焦STM32L系列MCU通过SPI2驱动1.3寸LCD的完整链路,涵盖Mode 阅读详情

相关推荐

TCS34725颜色识别模块实战调校:从“一坨”例程到精准RGB

本文针对TCS34725颜色识别模块初始数据不准的问题,提供了从基础例程到精准调校的实战指南。核心在于通过白光校正与黑白光校正两种方法,补偿传感器偏差与环境光影响,将原始数据准确映射为标准RGB值。文章详细阐述了校准原理、操作步骤与代码实现,并分享了进阶调试技巧与避坑指南,帮助开发者显著提升颜色识别的准确性与项目可靠性。

weixin_29188043的博客 290

leetcode题:726. 原子的数量(困难)

一、题目描述:726. 原子的数量(困难) 给定一个化学式formula(作为字符串),返回每种原子的数量。 原子总是以一个大写字母开始,接着跟随0个或任意个小写字母,表示原子的名字。 如果数量大于 1,原子后会跟着数字表示原子的数量。如果数量等于 1 则不会跟数字。例如,H2O 和 H2O2 是可行的,但 H1O2 这个表达是不可行的。 两个化学式连在一起是新的化学式。例如H2O2H...

tankpanv的博客 1034

基于Ultralytic实现多路摄像头目标检测

基于Ultralytic实现多路摄像头目标检测前面的文章分享了单路摄像头画面的YOLO目标检测,这篇文章主要分享一下多路摄像头画面的实时YOLO目标检测。测试环境在Windows系统下进行。

qq_57674776的博客 949

Number of Atoms--LeetCode

最近刷了一道算法题  Number of Atoms,原题链接Number of Atoms发现网上几乎没什么答案,可能是题号太靠后的原因吧,做出来之后收获挺多的,打算分享一下。 这道题的tag是HashTable、Stack和Recursion,拿到题的第一感觉就是有两种解法,一种是stack,一种是递归,两种解法都要用到hashTable。想到了数据结构与算法课学到的逆波兰式,决定用sta

chouchou680的博客 389

高通量测序数据分析:RNA-seq

深度测序相关数据库与数据格式 SRA toolkit 一、NCBI 和EBI、DDBJ组成INSDC,数据内容相同所以找NCBI就行。 (一)NCBI常用数据库 GenBank:遗传序列数据库,收集了所有公开的DNA序列及其注释 GEO (Gene Expression Omnibus) :收集整理各种表达芯片数据,后来加入了甲基化、lncRNA、miRNA、CNV等其他芯片,还有高通量测序数据...

qq_41134363的博客 3万+

【第三只眼:Oracle通过归档日志查看系统的业务高峰sql】

根据oracle归档的业务高峰量,查找业务sql,进行优化

霍然的专栏 583

【leetcode】726. Number of Atoms

题目如下: 解题思路:我用的是递归的方法,每次找出与第一个')'匹配的'('计算atom的数量后去除括号,只到分子式中没有括号为止。例如"K4(ON(SO3)2)2" -> "K4(ONS2O6)2" -> "K4O2N2S4O12"。接下来再对分子式进行分割,得出每个atom的数量后排序即可。原理很简单,代码写得很乱,仅供参考。 代码如下: class Solutio...

weixin_33701564的博客 211

Diffusion、VAE与GAN:三大生成模型的原理对比与应用场景解析

本文深入解析了Diffusion、VAE与GAN三大生成模型的核心原理与特性。Diffusion模型通过逆向去噪过程实现高质量图像生成,但计算成本较高;VAE擅长学习概率潜空间,训练稳定但图像偏模糊;GAN通过对抗训练生成锐利图像,但存在模式崩溃风险。文章结合实战场景,为图像生成、修复、超分辨率等任务提供了清晰的模型选择指南。

weixin_29063979的博客 353

LeetCode 化学公式解析 ( 递归 + 模拟 - 类压缩题型 )

LeetCode 7天刷题挑战:化学公式解析 万恶的模拟题 一开始以为是那种模拟运算操作的, 直接定义了两个栈开搞, 弄到一半发现模拟不出,因为有括号在影响 仔细再看这题就是压缩题型变形来的, 用递归解 题型: [编程题]压缩算法 大致思路: 先将输入的字符串的括号去掉, 递归实现,for 循环遍历 遇到左括号就递归到下一层, 从最里层解刨 将消除完括号的字符串统计word 和 对应的个数即可 AC Code import java.util.*; import static java.la

lankerens 904

微信小程序中使用画布canvas实现动态心电图绘制

近期,接了个项目,三端(小程序、PC、公众号)同步开发,PC端没的问题,以前一直做的就是PC端,但是小程序和公众号之前没有做过,只能通过这个项目,边做边学了。人家都说小程序用原生的特别难,大部分都用uniapp开发,说是这个方便快捷,还能写app呢,因为我们的项目,需要用到蓝牙采集数据、画布画仪表盘以及心电图等,所以我们不太敢用uniapp开发,硬着头皮开始用原生开发。开发的过程中,也遇到过很多问题,但是好在经过我们团队的不懈努力,问题基本都解决了。下面我就来分享一下,在小程序中,如何通过canvas。

穆雄雄的博客 3653

比值计算 - 荣耀机试真题题解 ( 第1题 100 分)

已知差值$ x=10*log10(S/N)-10*log10(S/(N+k*N)) $,计算10*log(k)并打印出来(整数即可) ### 输入描述 差值 x ### 输出描述 10*log10(k) 并打印出来(整数即可)

学习,你不是一个人在战斗 ~ 961302305(QQ,微信) 1571

LeetCode 726. 原子的数量 (困难)

726. 原子的数量 (困难) 给定一个化学式formula(作为字符串),返回每种原子的数量。 原子总是以一个大写字母开始,接着跟随0个或任意个小写字母,表示原子的名字。 如果数量大于 1,原子后会跟着数字表示原子的数量。如果数量等于 1 则不会跟数字。例如,H2O 和 H2O2 是可行的,但 H1O2 这个表达是不可行的。 两个化学式连在一起是新的化学式。例如 H2O2He3Mg4 也是化学式。 一个括号中的化学式和数字(可选择性添加)也是化学式。例如 (H2O2) 和 (H2O2)3 是化学式。

weixin_43913594的博客 510

基于STM32设计的遥控灭火消防小车_296

随着城市化进程的加速和火灾发生频率的增加,传统的消防方式在应对初期火灾时存在反应慢、效率低等问题。为了提高火灾响应速度和灭火效率,本设计开发了一款基于STM32单片机的遥控灭火消防小车。该小车配备了烟雾检测、温湿度监测、火源定位、灭火操作等功能,能够通过蓝牙和WIFI实现远程控制与实时视频传输。设计采用了MQ2烟雾传感器、SHT30温湿度传感器、火光传感器和ESP32摄像头模块等硬件设备。系统不仅能够自动检测和定位火源,还可以手动调整灭火器对准位置,进行干粉灭火。此外,蜂鸣器用于火源报警,确保操作人员及时得

733

Number of Atoms Leetcode #726 题解[C++]

题目来源 https://leetcode.com/problems/number-of-atoms/description/ 题意分析 Given a chemical formula (given as a string), return the count of each atom. An atomic element always starts with an upperc...

Wayne_Mai的博客 811

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

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

[Swift]LeetCode726. 原子的数量 | Number of Atoms

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)➤GitHub地址:https://github.com/strengthen/LeetCode➤原文地址:https://www.cnblogs.com/stren...

weixin_30597269的博客 155

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

LeetCode:726. Number of Atoms - Python

问题描述: 给定一个化学式formula(作为字符串),返回每种原子的数量。 原子总是以一个大写字母开始,接着跟随0个或任意个小写字母,表示原子的名字。 如果数量大于 1,原子后会跟着数字表示原子的数量。如果数量等于 1 则不会跟数字。例如,H2O 和 H2O2 是可行的,但 H1O2 这个表达是不可行的。 两个化学式连在一起是新的化学式。例如H2O2He3Mg4 也是化学式。 ...

Growth Diary 1422

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

leetcode 困难题 726. Number of Atoms 原子的数量

因数值过大,所以使用了unsigned long long类型i–;是for()循环内部还会i++,不减1的话会导致+2的情况

邹九的个人博客 218

Number of Atoms——LeetCode进阶路

原题链接https://leetcode.com/problems/number-of-atoms/ 题目描述 Given a chemical formula (given as a string), return the count of each atom. An atomic element always starts with an uppercase character, then...

Moliay的博客 329

LeetCode 726. Number of Atoms

题意:给出一个化合物的化学式 eg, Mg(OH)2 and K4(ON(SO3)2)2,统计出其每个原子的个数 很明显用递归做,如果遇到a(bcd)ef,则bcd构成一个子问题,递归处理统计出各个原子出现的频率(用map记录),如果e是个数字,返回后merge频率乘上该数字即可。 但是需要保证先处理外面的括号,再处理内部的括号e.g., (a(bdc)e)。我把一块当做merge intev...

TimeForMiracles 450

[LeetCode] Number of Atoms 原子的个数

Given a chemicalformula(given as a string), return the count of each atom. An atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name...

weixin_30725315的博客 133

LeetCode-726 原子的数量 递归

LeetCode-726 原子的数量 递归 题目链接:LeetCode-726 原子的数量 给你一个字符串化学式 formula ,返回 每种原子的数量 。 原子总是以一个大写字母开始,接着跟随 0 个或任意个小写字母,表示原子的名字。 如果数量大于 1,原子后会跟着数字表示原子的数量。如果数量等于 1 则不会跟数字。 例如,“H2O” 和 “H2O2” 是可行的,但 “H1O2” 这个表达是不可行的。 两个化学式连在一起可以构成新的化学式。 例如 “H2O2He3Mg4” 也是化学式。 由括号括起的化学

weixin_44966641的博客 5269

LeetCode——726. 原子的数量(Number of Atoms)[困难]——分析及代码(Java)

LeetCode——726. 原子的数量[Number of Atoms][困难]——分析及代码[Java]一、题目二、分析及代码1. 栈 + 哈希表 + 有序集合(1)思路(2)代码(3)结果三、其他 一、题目 给定一个化学式formula(作为字符串),返回每种原子的数量。 原子总是以一个大写字母开始,接着跟随0个或任意个小写字母,表示原子的名字。 如果数量大于 1,原子后会跟着数字表示原子的数量。如果数量等于 1 则不会跟数字。例如,H2O 和 H2O2 是可行的,但 H1O2 这个表达是不可行的。

江南土豆的博客 505

LeetCode 原子的数量(递归+hash表)

给定一个化学式formula(作为字符串),返回每种原子的数量。 原子总是以一个大写字母开始,接着跟随0个或任意个小写字母,表示原子的名字。 如果数量大于 1,原子后会跟着数字表示原子的数量。如果数量等于 1 则不会跟数字。例如,H2O 和 H2O2 是可行的,但 H1O2 这个表达是不可行的。 两个化学式连在一起是新的化学式。例如 H2O2He3Mg4 也是化学式。 一个括号中的化学式和数字(可...

hestyle的博客 1763

[LeetCode]726. Number of Atoms

题意:给定一个以字符串表示的化学表达式,求表达式中每个原子及其个数。 思路:递归,也可以用栈,一样的思路。

哈哈哈哈嘿嘿嘿 1569

leetcode_726. Number of Atoms ? 待解决

Given a chemical formula (given as a string), return the count of each atom.An atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.1 or

wjheha的博客 634

leetcode 726. 原子的数量

递归+非递归 递归: 遇到左括号是进行递归,之后返回子串的结果加到总结果中 非递归: 遇到左括号进行压栈,遇到右括号弹栈至出现一个左括号 #include&amp;lt;cstdio&amp;gt; #include&amp;lt;cstring&amp;gt; #include&amp;lt;algorithm&amp;gt; #include&amp;lt;iostream&amp;gt; #include&amp;lt;

DUT_LYH 3万+
上一篇: leetcode 730. Count Different Palindromic Subsequences 回文子序列的数量+动态规划DP
下一篇: leetcode 685. Redundant Connection II 有向图的环的查询 + 并查集Union Find
JackZhangNJU
博客等级 码龄12年 105粉丝 716原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值