문제 :
Write a function that reverses a string. The input string is given as an array of characters s.
You must do this by modifying the input array in-place with O(1) extra memory.
- 주어진 문자형 배열 s를 수정하여 return (in-place)
- O(1)의 시간복잡도를 가진 추가 메모리만을 활용하여 풀기
*O(1) - 일정한 복잡도(constant complexity)
: 입력값이 증가하더라도 시간이 늘어나지 않는다.
풀이 :
/**
* @param {character[]} s
* @return {void} Do not return anything, modify s in-place instead.
*/
var reverseString = function(s) {
return s.reverse();
};
'Algorithm' 카테고리의 다른 글
[LeetCode] Merge Sorted Array (0) | 2023.09.11 |
---|---|
[LeetCode] Delete Node in a Linked List (js/연결 리스트) (0) | 2023.09.11 |
[LeetCode] Single Number (Map()을 활용해 풀기) (0) | 2023.09.07 |
[LeetCode] Contains Duplicate (3가지 풀이방법) (0) | 2023.09.06 |
[LeetCode]Best Time to Buy and Sell Stock II (0) | 2023.09.01 |