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 | 31 |
Tags
- npm package
- 이미지 데이터 타입
- vercel git lfs
- animation
- ffi-napi
- electron-packager
- adb connect
- github pdf
- nextjs
- augmentedDevice
- Can't resolve
- ELECTRON
- rolldown
- react-native-dotenv
- github 100mb
- Failed to compiled
- Each child in a list should have a unique "key" prop.
- silent printing
- dvh
- custom printing
- camera permission
- adb pair
- camera access
- Git
- react-native
- device in use
- github lfs
- Recoil
- html
- 티스토리 성능
Archives
- Today
- Total
Bleeding edge
[프로그래머스] 괄호 회전하기 - 자바스크립트 본문
https://programmers.co.kr/learn/courses/30/lessons/76502
코딩테스트 연습 - 괄호 회전하기
programmers.co.kr
한가지 사항을 기억하는데 시간이 좀 걸렸었다. 바로 이스케이프 코드를 정규식에 사용하는 방법.
const regex = /[\(\)]/g 다음과 같이, 각 이스케이프마다 한번씩 쓰는걸 깜빡해서.. 5분정도 regex match에 시간을 섰다.. regex를 처음 쓸때는 ()와 []많이 헷갈렸었는데 이제는 쓰다보니 연상 암기를 할 수 있게 된거같다
[]의 괄호 []는 array와 같으니, 각 개체를 split해서 구분한다.
()의 괄호는, function의 var을 담는 괄호와 같으니 join해서 구분한다!로 연상하니 납득이 됬다. 아참. 문제풀이는 다음과 같다
function solution(s) {
var answer = 0;
let list = check(s)
const regex1 = /(\(\))/g
const regex2 = /(\{\})/g
const regex3 = /(\[\])/g
for(let i = 0; i<list.length;i++){
let num=0
while(list[i].match(regex1)||list[i].match(regex2)||list[i].match(regex3)){
list[i]= list[i].replace(regex1, '').replace(regex2, '').replace(regex3, '');
}
if(list[i].length===0){
answer++
}
}
return answer;
}
function check (s){
s = s.split('')
const list = [];
const num = s.length;
for(let i =0; i<num;i++){
let temp = s.shift();
s.push(temp)
list.push(s.join(''))
}
return list
}
'코딩테스트 공부' 카테고리의 다른 글
[프로그래머스] 삼각 달팽이 - 자바스크립트 (0) | 2022.04.20 |
---|---|
[프로그래머스] - 124 나라의 숫자 (0) | 2022.04.19 |
[프로그래머스] 땅따먹기 - 자바스크립트 (0) | 2022.04.17 |
[프로그래머스] 이진 변환 반복하기 - 자바스크립트 (0) | 2022.04.15 |
[프로그래머스] 스킬트리 - 자바스크립트 (0) | 2022.04.13 |