当前位置:网站首页>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)
边栏推荐
- Leetcode-112: path sum
- SQL Server Management Studio cannot be opened
- Tensorflow—Neural Style Transfer
- 2018 Lenovo y7000 black apple external display scheme
- 侯捷——STL源码剖析 笔记
- 熵值法求权重
- Leetcode刷题---189
- Seata分布式事务失效,不生效(事务不回滚)的常见场景
- 【毕业季】图匮于丰,防俭于逸;治不忘乱,安不忘危。
- Linear regression of introduction to deep learning (pytorch)
猜你喜欢
ThreadLocal原理及使用场景
Leetcode-112: path sum
Ut2017 learning notes
Ut2016 learning notes
Data classification: support vector machine
2018 y7000 upgrade hard disk + migrate and upgrade black apple
Linear regression of introduction to deep learning (pytorch)
Out of the box high color background system
丢弃法Dropout(Pytorch)
Policy Gradient Methods of Deep Reinforcement Learning (Part Two)
随机推荐
Pytorch ADDA code learning notes
Leetcode-112: path sum
Multilayer perceptron (pytorch)
Hands on deep learning pytorch version exercise solution - 2.5 automatic differentiation
2018 y7000 upgrade hard disk + migrate and upgrade black apple
Leetcode - the k-th element in 703 data flow (design priority queue)
Raspberry pie 4B deploys lnmp+tor and builds a website on dark web
Leetcode刷题---44
Leetcode刷题---374
Realize an online examination system from zero
Policy gradient Method of Deep Reinforcement learning (Part One)
20220607 others: sum of two integers
Model selection for neural network introduction (pytorch)
Softmax 回归(PyTorch)
Label Semantic Aware Pre-training for Few-shot Text Classification
神经网络入门之模型选择(PyTorch)
[LZY learning notes dive into deep learning] 3.1-3.3 principle and implementation of linear regression
What useful materials have I learned from when installing QT
八、MySQL之事务控制语言
20220531 Mathematics: Happy numbers