Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions leetcode3/정진영/1202. Smallest String With Swaps
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @param {string} s
* @param {number[][]} pairs
* @return {string}
*/
var smallestStringWithSwaps = function(s, pairs) {
/*
1. 아이디어
- pairs를 이용해 인덱스 간 연결 관계를 만든다
- dfs 로 서로 연결된 인덱스를 찾는다
- 연결된 인덱스에 해당하는 문자들을 오름차순 정렬 후 반환
2. 시간복잡도

3. 자료구조
- chk : 이미 방문한 인덱스인지 확인용
-
*/

let graph = Array.from({ length: s.length }, () => []);
let chk = Array.from(s.length).fill(0);


for (let i = 0; i < pairs.length; i++) {
let a = pairs[i][0];
let b = pairs[i][1];

graph[a].push(b);
graph[b].push(a);
}

};
Loading