Last active
July 4, 2023 07:53
-
-
Save dalinaum/7ba4988d2f66aa519b2f21d80c581e69 to your computer and use it in GitHub Desktop.
programmer 181921
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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