Skip to content

Instantly share code, notes, and snippets.

@dalinaum
Last active July 4, 2023 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalinaum/7ba4988d2f66aa519b2f21d80c581e69 to your computer and use it in GitHub Desktop.
Save dalinaum/7ba4988d2f66aa519b2f21d80c581e69 to your computer and use it in GitHub Desktop.
programmer 181921
import java.util.ArrayList;
class Solution {
public int[] solution(int l, int r) {
ArrayList<Integer> result = new ArrayList();
for (int i = l; i <= r; ++i) {
String value = String.valueOf(i);
boolean matched = true;
for (int j = 0; j < value.length(); ++j) {
char current = value.charAt(j);
if (current != '0' && current != '5') {
matched = false;
break;
}
}
if (matched) {
result.add(i);
}
}
if (result.isEmpty()) {
return new int[] { -1 };
}
// 스트림 버전
return result.stream().mapToInt(it -> it).toArray();
}
}
import java.util.ArrayList;
class Solution {
public int[] solution(int l, int r) {
ArrayList<Integer> result = new ArrayList();
for (int i = l; i <= r; ++i) {
String value = String.valueOf(i);
boolean matched = true;
for (int j = 0; j < value.length(); ++j) {
char current = value.charAt(j);
if (current != '0' && current != '5') {
matched = false;
break;
}
}
if (matched) {
result.add(i);
}
}
if (result.isEmpty()) {
return new int[] { -1 };
}
// 스트림 없는 버전
int[] answer = new int[result.size()];
for (int i = 0; i < result.size(); ++i) {
answer[i] = result.get(i);
}
return answer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment