当前位置:网站首页>Likou Question of the Day - Day 46 - 344. Reverse Strings
Likou Question of the Day - Day 46 - 344. Reverse Strings
2022-08-02 23:02:00 【Heavy Mail Research Sen】
2022.8.2 Did you write the questions today?
Title:
Write a function that reverses the input string.The input string is given as a character array s.
Don't allocate extra space for another array, you have to modify the input array in place, using O(1) extra space to solve this problem.
Analysis:
Given a vector array of char, no new space memory can be generated to reverse the original string.
Ideas: The simplest idea: a reverse!!!Of course, that makes no sense.So our idea is:
Use two pointers, one from the left and one from the right, and use a temp as an intermediate variable.Swap two values until left >= right.
Analysis:
1. Double pointer
class Solution {public:void reverseString(vector& s) {int left = 0;int right = s.size() - 1;char temp;while (left < right){temp = s[left];s[left] = s[right];s[right] = temp;left++;right--;}}}; 2.reverse
class Solution {public:void reverseString(vector& s) {reverse(s.begin(),s.end());}}; 边栏推荐
猜你喜欢
随机推荐
ECCV 2022 | 通往数据高效的Transformer目标检测器
使用位运算实现加减乘除(+、-、*、/)及比较器的用法
Three.js入门
el-tree渲染大量数据的解决方案(不通过懒加载)
基于 outline 实现头像剪裁以及预览
[AnXun cup 2019] easy_web
Redis集群配置
SQL Server数据类型转换函数cast()和convert()详解
我用这一招让团队的开发效率提升了 100%!
4KMILES加入艾盛集团,以更强劲的数字商务能力,加速中国跨境电商的全域全效增长
【数据分析】:什么是数据分析?
Fiddle设置接口数据用指定工具查看;Sublime Text设置json数据格式化转换
Translate My Wonderful | July Moli Translation Program Winners Announced
LeetCode - 105. 从前序与中序遍历序列构造二叉树;023.合并K个升序链表
Caldera(二)高级实战
js Fetch返回数据res.json()报错问题
技术分享 | Apache Linkis 快速集成网页IDE工具 Scriptis
golang刷leetcode 动态规划(13) 最长公共子序列
扫码预约 | 观看Apache Linkis数据处理实践以及计算治理能力
golang刷leetcode 数学(1) 丑数系列









