You are viewing a single comment's thread. Return to all comments →
I didn't pass the last 2 test cases and got a run time error for the last test case. Could anyone find the bug in my solution?
import java.io.; import java.util.;
public class Solution {
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); String out = ""; while(T-- > 0) { int key = sc.nextInt(); if(key % 3 == 0) { out = new String(new char[key]).replace("\0", "5"); } else { int x = key; while(x % 3 != 0 && x > 0) { x -= 5; } if(x%3 == 0) { String fives = new String(new char[x]).replace("\0", "5"); String threes = new String(new char[key-x]).replace("\0", "3"); out = fives+threes; } else if(x == 0) { out = new String(new char[key]).replace("\0", "3"); } else out = "-1"; } System.out.println(out); } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and The Beast
You are viewing a single comment's thread. Return to all comments →
I didn't pass the last 2 test cases and got a run time error for the last test case. Could anyone find the bug in my solution?
import java.io.; import java.util.;
public class Solution {
}