
g0301_0400.s0344_reverse_string.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
package g0301_0400.s0344_reverse_string;
// #Easy #Top_Interview_Questions #String #Two_Pointers #Recursion #Algorithm_I_Day_4_Two_Pointers
// #2022_03_15_Time_1_ms_(87.94%)_Space_54.6_MB_(42.01%)
public class Solution {
public void reverseString(char[] s) {
int left = 0;
int right = s.length - 1;
while (left < right) {
char tmp = s[left];
s[left++] = s[right];
s[right--] = tmp;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy