Algorithm/LeetCode

[string] reverse string

sw_develop 2025. 3. 8. 11:18

 Problem

https://leetcode.com/problems/reverse-string/description/

 

 Approach & Solution

방식)

더보기
  • 주어진 배열 내부에서 직접 조작
class Solution {
    public void reverseString(char[] s) {
        int start = 0;
        int end = s.length - 1;

        while (start < end) {
            char tmp = s[start];
            s[start] = s[end];
            s[end] = tmp;

            start++;
            end--;
        }
    }
}