인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

pokerface5821412's profile image
pokerface5821412

asked

Coding test top basic problems that are really easy to solve (with Java)

RemoveInvalidParentheses

새로운 풀이법 문의

Written on

·

307

2

public List<String> solve(String s) {
List<String> result = new ArrayList<>();
if (s == null)
return result;

for (int i = 0; i < s.length(); i++) {
String newStr = s.substring(0, i) + s.substring(i + 1);
if (isValid(newStr) && !result.contains(newStr)) {
result.add(newStr);
}
}
return result;
}

위와 같이 풀어보았는데 같은 결과가 나옵니다.

강사님의 substring 과 isValid를 이용했습니다.

엄청 단순해졌는데,,

혹시 이 풀이에 문제가있을까요

그런데 신기한게 해당 문제로 검색해서 다른풀이들을 보면 모두 강사님처럼 DFS로 풀었습니다.

저처럼 잘모르는 사람이 쉽게 가보려고 얍삽이?를 쓴것처럼 한 경우는없습니다.

왜그런것인가요?

java코테 준비 같이 해요!

Answer 2

0

 시간복잡도 제한이 있다면 성능에 집중하고 없다면 창의적으로, ,, 좋은 조언 감사합니다

0

pushupman님의 프로필 이미지
pushupman
Instructor

안녕하세요 

답만 구하면 상관없죠 ^^*
문제에서 time complexity 제한조건이 없는한 창의적인 방식으로 풀면 더 가산좀이 있죠

pokerface5821412's profile image
pokerface5821412

asked

Ask a question