TIL/Coding Test
[LeetCode] Reverse String
재조(jazzo)
2021. 3. 9. 21:32
반응형
오늘의 문제 2. 빛줄기 언니가 다른 문제를 하나 더 내줬다. 전에 풀었던 문제랑 푸는 방법이 비슷했다.
간략하게 설명하자면 char 요소들로 이루어진 배열을 거꾸로 뒤집는 문제.
Explore - LeetCode
LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.
leetcode.com
public class cote0309_250_principleOfRecursion_1440_ReverseString {
public void reverseString(char[] s) {
int end=s.length-1;
int start=0;
while(start < s.length/2){
char temp=s[start];
s[start]=s[end];
s[end]=temp;
start++;
end--;
}//스타트 엔드 정수를 이용하는게 좀 익숙해진거 같다. 보자마자 생각나서 해봤는데 억셉돼서 기뻤음
//temp를 쓰지 않는 방법은?
}
}
728x90
반응형