[Leetcode] 344. Reverse String

Ubuntu22.04下,用Fast-LIVO2+3DGS重建桌面小物件:从点云到高清模型的保姆级避坑实录 本文详细介绍了在Ubuntu22.04环境下,使用Fast-LIVO2与3DGS技术进行桌面小物件三维重建的完整流程。从环境配置、数据采集到点云-图像对齐和3DGS训练,提供了针对小物件优化的参数设置和避坑指南,帮助用户实现媲美商业扫描仪的高清模型重建效果。 阅读详情

Description:
Write a function that takes a string as input and returns the string reversed.

Example:
Given s = “hello”, return “olleh”.

考虑空字符串,也属于reversed string.

解法一:
基本思想:对撞指针。
思路:从头从尾分别同时遍历,每次swap,直到相遇或cross over。
Time: O(n)O(n)
Space: O(1)O(1)

class Solution {
public:
    string reverseString(string s) {

        if(s.size() == 0)//处理空字符串
            return s;

        for(int i = 0, j = s.size()-1; i < j; i++, j--){//只要i<j,就可以判断是否相同然后swap
            if(s[i]!=s[j])//避免unnecessary swap
                swap(s[i],s[j]);
        }
        return s;
    }
};

解法二:
基本思想:栈。
思想:这道题也可以用栈来实现。虽然过程复杂了点,还开辟了一段栈空间,但是为了实践一下也实现了。
关于栈的使用:

.empty() //堆栈为空则返回真
.pop() //移除栈顶元素
.push(x) //在栈顶增加元素
.size() //返回栈中元素数目
.top() //返回栈顶元素

Time: O(n)O(n)
Space:O(n)O(n) (开辟了一段栈空间)

class Solution {
public:
    string reverseString(string s) {

        if(s.size() == 0)
            return s;

        stack<char> store;

        for(int i = 0; i <= s.size()-1; i++)//推入栈
            store.push(s[i]); 

        for(int i = 0; i <= s.size()-1; i++){//弹栈
            s[i] = store.top();
            store.pop();
        }
        return s;
    }
};
RTKLIB使用方法(喂饭版)(三)——RTKPOST 应用OTL校正需要在“files”的“ocean loading BLQ format”中配置OTL文件。应用极潮需要在“files”的“EOP data file”配置ERP(地球旋转参数)文件。RAIM FDE:设置是否启用RAIM(接收机自主完整性监控)FDE(故障检测和排除)功能。点击下方的“save”可以把配置保存成文件,点击“load”就可以把配置文件加载出来。4接收机动态模型/地球潮汐矫正:设置流动站接收机动力学模型,只可以使用在DGPS/DGNSS或动态模型中。选择流动站天线的类型。 阅读详情

相关推荐

关于无障碍适配的笔记

针对无障碍兼容性的笔记,针对wcg2.0/2.1

CoffeeAndIce的博客 4211

[LeetCode]344. Reverse String

[LeetCode]344. Reverse String题目描述思路水题,栈代码class Solution { public: string reverseString(string s) { stack<char> rev; string result = ""; for (char &p : s){ rev.pu

Lcharon的博客 3179

containerd镜像加速配置全解析:从host.toml到config.toml的演进与实践

本文全面解析了containerd镜像加速的配置方法,重点对比了传统的config.toml集中式配置与现代的host.toml模块化配置的演进与优劣。文章通过实战演示,详细指导如何为docker.io、registry.k8s.io等常见仓库配置host.toml加速,并提供了生产环境下的最佳实践、故障排查与性能优化建议,帮助用户显著提升镜像拉取效率与系统稳定性。

jenkins8butler的博客 698

[LeetCode] 344 Reverse String && 541 Reverse String II

原题地址: 344Reverse String: https://leetcode.com/problems/reverse-string/description/ 541Reverse String II: https://leetcode.com/problems/reverse-string-ii/description/ 题目&&解法: 1....

aixian8156的博客 145

AICodeing:AI驱动的全栈开发革命

作为阿里/字节跳动的资深Java工程师,我们正站在研发效能革命的临界点上。本文将深入探讨如何利用AI技术重构全栈开发流程,实现从需求到上线的量子级提速。

weixin_43290370的博客 1134

OpenPCDet安装及其3D检测算法实现

OpenPCDet及pointpillar复现

weixin_58207716的博客 1万+

LeetCode 344 Reverse String

LeetCode 344 Reverse String#include <string> using namespace std;class Solution { public: string reverseString(string s) { int i = 0; int j = s.size() - 1; while (i < j)

自己的学习笔记 339

手把手教你用STM32F103的GPIO模拟MIPI RFFE协议(附完整代码与逻辑分析仪调试技巧)

本文详细解析了如何使用STM32F103的GPIO模拟MIPI RFFE协议,包括协议核心、硬件准备、时序模拟、寄存器操作及逻辑分析仪调试技巧。通过实战代码和波形分析,帮助工程师解决电平转换、奇校验处理等常见问题,提升通信稳定性与效率。

weixin_30292745的博客 284

[leetcode]344. Reverse String

[leetcode]344. Reverse String Analysis 周五啦,端午小长假要开始啦~—— [嘻嘻~] Write a function that takes a string as input and returns the string reversed. 反转string Implement 方法一:(space complexity O(N))...

weixin_32135877的博客 138

统计学习导论(ISLR) 第四章分类算法课后习题

统计学习导论(ISLR) 参考资料: The Elements of Statistical Learning An Introduction to Statistical Learning 统计学习导论(ISLR)(二):统计学习概述 统计学习导论(ISLR)(三):线性回归 统计学习导论(ISLR)(四):分类 ISLR统计学习导论之R语言应用(二):R语言基础 ISLR统计学习导论之R语言应用(三):线性回归R语言代码实战 ISLR统计学习导论之R语言应用(四):分类算法R语言代码实战 统计学习导论

阿里云专家博主、数据科学领域优质创作者、统计er在读 2万+

196、NPU的编译器开发:教程与示例代码编写

NPU编译器开发实战指南 摘要:本文分享了NPU编译器开发中的核心挑战与实战经验,通过具体代码示例展示了关键实现技术: 指令生成:必须考虑硬件特性(如地址对齐)和芯片配置抽象化 图优化:重点处理常见冗余结构(Reshape合并、BN融合),并注意数值稳定性 算子拆分:采用分块计算策略适配有限SRAM,需特别注意边界条件处理 内存分配:基于张量使用频率的贪心算法优化SRAM使用效率 文中包含多个真实踩坑案例: DMA地址未对齐导致硬件错误 BN融合时的除零风险 tile边界处理不当引起的精度下降 这些经验为开

m0_50546716的博客 74

Leetcode 344. Reverse String (Easy) (cpp)

Leetcode 344. Reverse String (Easy) (cpp)

还是需要多学习!闷声大发财,这是坠吼的! 3245

【Matlab】从零开始掌握 MATLAB 安装激活:从环境搭建到问题解决全指南

打开 MATLAB,点击 “主页 - 设置路径”;点击 “添加文件夹”,选择自定义的工作文件夹,点击 “保存”,重启 MATLAB 生效。MATLAB R2024a 的安装与激活是开启 MATLAB 学习的第一步,也是构建稳定学习环境的基础。本文从安装前准备、分步操作、验证测试、问题解决到环境优化,完整覆盖了新手所需的所有知识点 —— 核心要点在于:确认系统兼容、使用合法授权、选择纯英文安装路径、完成功能验证。

unber的博客 596

LeetCode: 344. Reverse String

LeetCode: 344. Reverse String Write a function that takes a string as input and returns the string reversed. Example: Given s = “hello”, return “olleh”. public class Solution { public Str

qha0731的专栏 302

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Task4:LeetCode1:twoSum; LeetCode344:Reverse String;LeetCode151:Reverse Words in a String

1.Two Sum(两个数求和) class Solution: def twoSum(self, nums: 'List[int]', target: int) -> 'List[int]': dicti = {} for i, n in enumerate(nums): if n in dicti: ...

m0_37548423的博客 168

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

中国铁路网矢量shp数据获取与处理实战:从坐标系到缓冲区分析

在GIS工程中,矢量数据是空间分析的基石,而铁路网作为线性要素,其shp数据的质量直接决定项目成败。Shapefile由几何、索引与属性表等多个文件构成,坐标系(WGS84、CGCS2000、GCJ02)的混乱是数据不可用的头号原因。通过OpenStreetMap与国家基础地理信息中心等正规渠道获取的铁路网数据,经投影转换、拓扑修复与属性清洗后,可用于缓冲区分析、物流选址及人口覆盖评估。本文结合真实项目经验,详解从数据获取、QGIS/ArcGIS预处理到多源数据融合的完整链路,帮助读者避开坐标系错乱、属性乱

weixin_34129696的博客 338

深度学习工具包 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——344. Reverse String(字符串反转)

题目链接 题目: 344. Reverse String DescriptionHintsSubmissionsDiscussSolution DiscussPick One Write a function that takes a string as input and retur

David_Jett 610

Leetcode #344 Reverse String

问题描述: Write a function that takes a string as input and returns the string reversed. 思路: (最近做水题做上瘾了) 交换数字可以用异或啊啊啊啊啊啊啊啊啊 代码: class Solution { public: string reverseString(st

小昕成长史 202

LeetCode344—Reverse String

LeetCode344—Reverse String

上善若水 769

Leetcode 344 Reverse String

Leetcode 344 Reverse String 题目描述 Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by...

qq_43271202的博客 209

LeetCode【#344】Reverse String

题目链接: 点击跳转 题目: Write a function that reverses a string. The input string is given as an array of characterschar[]. Do not allocate extra space for another array, you must do this bymodifying...

Mikchy的博客 298

LeetCode 344.Reverse String

题意: Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh". 实现字符串的反转。 刚开始时,我是直接string fan,然后给...

aichon2012的博客 1395

【leetcode】344. Reverse String

problem 344. Reverse String solution: class Solution { public: void reverseString(vector<char>& s) { vector<char> temp(s.size(), '0'); for(int i=s.size()-...

weixin_30767835的博客 94

【LeetCode】344. Reverse String 解题报告

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51416284Subject 出处:https://leetcode.com/problems/reverse-string/ Write a function that takes a string as input and returns the string rever

crazy_jack 1万+

LeetCode344 Reverse String

题目: Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying th...

zhangjun62的博客 123

LeetCode 344: Reverse String 题解

从今天开始我也来刷刷 LeetCode,从最简单的题开始。LeetCode 344: Reverse StringProblem: Write a function that takes a string as input and returns the string reversed. Example: Given s = “hello”, return “olleh”.这道题很简单,就

请叫我AXin 1436
上一篇: [Leetcode] 125. Valid Palindrome
下一篇: [Leetcode] 345. Reverse Vowels of a String
Peggy_Chang
博客等级 码龄11年 21粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值