Topic: Queue
Questions Successfully Completed: 1
1) Generate Binary Number | Easy |
Question
Input: N = 5 Output: 1 10 11 100 101 Explanation: Binary numbers from 1 to 5 are 1 , 10 , 11 , 100 and 101.
static ArrayList<String> generate(int N)
{
ArrayList<String> al = new ArrayList<>();
int index = 1;
while(index<=N){
String result = Integer.toBinaryString(index);
al.add(result);
index++;
}
return al;
}
Thank you for reading :)