Untitled
unknown
java
7 months ago
1.0 kB
7
Indexable
Never
import java.util.*; public class Solution { public static List<Integer> find123Digits(int[] arr, int n) { //You can code here List<Integer> result = new ArrayList<>(); for(int i=0;i<arr.length;i++) { int element = arr[i]; boolean foundOne=false; boolean foundTwo=false; boolean foundThree=false; String str=Integer.toString(element); for(int j=0;j<str.length();j++) { if (str.charAt(j) == '1') foundOne=true; else if(str.charAt(j)=='2') foundTwo=true; else if(str.charAt(j)=='3') foundThree=true; } if(foundOne && foundTwo && foundThree) { result.add(arr[i]); } } if(result.isEmpty()){ result.add(-1); } Collections.sort(result); return result; } }
Leave a Comment