当前位置:网站首页>Leetcode skimming ---202
Leetcode skimming ---202
2022-07-03 10:35:00 【Long time no see 0327】
subject : Write a function , Its function is to invert the input string . Input string as character array s Given in the form of . Do not allocate extra space to another array , You have to modify the input array in place 、 Use O(1) To solve this problem .
Input :s = ["h","e","l","l","o"]
Output :["o","l","l","e","h"]
Method 2 : Double pointer
class Solution {
public:
void reverseString(vector<char>& s) {
int n = s.size();
for (int left = 0, right = n -1; left < right; left++, right--) {
swap(s[left], s[right]);
}
}
};Complexity analysis
Time complexity :O(N)
Spatial complexity :O(1)
边栏推荐
- Adaptive Propagation Graph Convolutional Network
- Matrix calculation of Neural Network Introduction (pytoch)
- Several problems encountered in installing MySQL under MAC system
- C#项目-寝室管理系统(1)
- What can I do to exit the current operation and confirm it twice?
- [LZY learning notes dive into deep learning] 3.5 image classification dataset fashion MNIST
- Leetcode刷题---704
- 20220610 other: Task Scheduler
- Leetcode刷题---263
- EFFICIENT PROBABILISTIC LOGIC REASONING WITH GRAPH NEURAL NETWORKS
猜你喜欢

多层感知机(PyTorch)

Implementation of "quick start electronic" window dragging

Flutter 退出当前操作二次确认怎么做才更优雅?

Boston house price forecast (tensorflow2.9 practice)

Data preprocessing - Data Mining 1

3.3 Monte Carlo Methods: case study: Blackjack of Policy Improvement of on- & off-policy Evaluation

Simple real-time gesture recognition based on OpenCV (including code)

Automatic derivation of introduction to deep learning (pytoch)

Training effects of different data sets (yolov5)

Leetcode-106: construct a binary tree according to the sequence of middle and later traversal
随机推荐
Ind yff first week
Judging the connectivity of undirected graphs by the method of similar Union and set search
What can I do to exit the current operation and confirm it twice?
实战篇:Oracle 数据库标准版(SE)转换为企业版(EE)
ECMAScript -- "ES6 syntax specification # Day1
Leetcode刷题---10
Leetcode-100: same tree
Leetcode-404: sum of left leaves
重写波士顿房价预测任务(使用飞桨paddlepaddle)
Ut2015 learning notes
Introduction to deep learning linear algebra (pytorch)
深度学习入门之线性代数(PyTorch)
Leetcode刷题---1385
Raspberry pie 4B deploys lnmp+tor and builds a website on dark web
Free online markdown to write a good resume
二分查找法
Tensorflow—Neural Style Transfer
Leetcode-513: find the lower left corner value of the tree
侯捷——STL源码剖析 笔记
八、MySQL之事务控制语言