I haven't updated my blog for a long time. When I interviewed some candidate, I found that many of my friendsAlgorithmThe problem is always difficult. It may be the reason why there are not many problems in your work. Let's review some typical algorithms.
This algorithm should be optimal in terms of time complexity and minimum space usage.
N/2 times of array execution in time
Space Operations are only performed in the original array
Code
1 /**/ /// <Summary>
2 /// Reverse String Array
3 /// </Summary>
4 /// <Param name = "strsource"> Original String Array </Param>
5 /// <Returns> Returned results </Returns>
6 Public String [] Reverseword ( String [] Strsource)
7 {
8
9 // Calculate the number of times to traverse
10 Int Count = Strsource. Length % 2 = 1 ? (Strsource. Length - 1 ) / 2 : Strsource. Length / 2 ;
11 // Index of the last digit of the array
12 Int Length = Strsource. Length - 1 ;
13 // Temporary Variable
14 String Tempstring = String . Empty;
15
16 For ( Int I = 0 ; I < Count; I ++ )
17 {
18 Tempstring = Strsource [I];
19 Strsource [I] = Strsource [Length - I];
20 Strsource [Length - I] = Tempstring;
21 }
22 Return Strsource;
23 }