-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo344_String.cs
52 lines (49 loc) · 1.56 KB
/
No344_String.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Text;
namespace LeetCode_344
{
//static void Main(string[] args)
//{
// var solution = new Solution();
// while (true)
// {
// //int input = int.Parse(Console.ReadLine());
// //int input2 = int.Parse(Console.ReadLine());
// //int input3 = int.Parse(Console.ReadLine());
// //string input = Console.ReadLine();
// //string input = "A man, a plan, a canal: Panama";
// //string input2 = Console.ReadLine();
// //int[] intArr = input.Split(',').Select(s => int.Parse(s)).ToArray();
// //int input2 = int.Parse(Console.ReadLine());
// //int[] intArr = new int[] { 1, 3, 2 };
// //int[] intArr = new int[] { 1, 3 };
// char[] charArr = new char[] { 'h', 'e', 'l', 'l', 'o' };
// solution.ReverseString(charArr);
// //ConsoleX.WriteLine(res);
// }
//}
public class Solution
{
/// <summary>
/// 第一反应解,简单的交换
/// 时间复杂度:O(n)
/// 空间复杂度:O(1)
/// </summary>
/// <param name="s"></param>
public void ReverseString(char[] s)
{
int left = 0;
int right = s.Length - 1;
char temp;
while (left < right)
{
temp = s[left];
s[left] = s[right];
s[right] = temp;
left++;
right--;
}
}
}
}