Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |
Tags
- DP
- 리트코드
- sliding window
- 완전탐색
- two pointers
- 탐욕알고리즘
- 코테
- javascript
- 투포인터
- Binary Search
- 컴퓨터과학과
- dynamic programming
- 이진탐색
- algorithm
- 방송대
- 코딩
- 알고리즘
- java
- 깃
- greedy
- LeetCode
- 자바
- it
- Git
- 방통대
- 백준
- boj
- 자바스크립트
- 그리디
- 방송통신대학교
Archives
- Today
- Total
개발이 취미인 주니어 기획자
[투포인터][JavaScript][LeetCode] #557. Reverse Words in a String III 본문
문제 풀이/알고리즘 문제 풀이
[투포인터][JavaScript][LeetCode] #557. Reverse Words in a String III
큐 2023. 4. 1. 14:00728x90
반응형
#투포인터 #EASY
Reverse Words in a String III - LeetCode
Can you solve this real interview question? Reverse Words in a String III - Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Example 1: Input: s = "Let's take Leet
leetcode.com
🌷 문제 설명
✏️ LeetCode 연습문제: Reverse Words in a String III
Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
🎃 제한 사항
1 <= s.length <= 5 * 10^4
s contains printable ASCII characters.
s does not contain any leading or trailing spaces.
There is at least one word in s.
All the words in s are separated by a single space.
입출력 예
| s | result |
| "Let's Take LeetCode contest" | "s'teL ekat edoCteeL tsetnoc" |
| "God Ding" | "doG gniD" |
🌷 내 코드
1. 투포인터

var reverseWords = function(s) {
let word = s.split(' ')
for (let i=0; i<word.length; i++) {
let left = 0;
let right = word[i].length-1;
let al = word[i].split('')
while (left < right) {
let temp = al[left]
al[left] = al[right]
al[right] = temp
left++
right--
}
word[i] = al.join('')
}
return word.join(' ')
}
2. 무지성

var reverseWords = function(s) {
arr = s.split(' ')
answer = []
for (let i=0; i < arr.length; i++) {
answer.push(arr[i].split('').reverse().join(''))
}
return answer.join(' ')
}
🌷 코멘트
ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
투포인터 쓴게 더 느려서... 뭐가 잘못된거같아서 다른 사람들 코드를 넣어봤는데 효율성 더 안좋음;;;;; 뭘까 메모리 조금 덜 쓴거 정도..? 그렇다고 엄청 드라마틱한 변화 같진 않은데.... 알려 줄 사람 어디없나 😇
블로그 내용에 문제가 있다면 댓글 혹은 아래로 연락주세요!
~대가리 꽃밭인 디지털 노마드가 꿈이예요~
🧚♀️ Gyumin Lee
📧 gyumin.q.lee@gmail.com
qminlee723 - Overview
noob. qminlee723 has 8 repositories available. Follow their code on GitHub.
github.com
728x90
반응형
'문제 풀이 > 알고리즘 문제 풀이' 카테고리의 다른 글
| [투포인터][JavaScript][LeetCode] #167. Two Sum II - Input Array Is Sorted (0) | 2023.04.02 |
|---|---|
| [투포인터][JavaScript][LeetCode] #1480. Running Sum of 1d Array (0) | 2023.04.02 |
| [투포인터][JavaScript][LeetCode] #344. Reverse String (0) | 2023.04.01 |
| [투포인터][JavaScript][LeetCode] #283. Move Zeros (0) | 2023.03.31 |
| [투포인터][JavaScript][LeetCode] #977. Squares of a Sorted Array (0) | 2023.03.30 |