fork download
  1. class Solution {
  2. public static boolean check(int mid,int n){
  3. long count=(long)mid*(mid+1)/2;
  4.  
  5. if(count <= n){
  6. return true;
  7. }
  8. else{
  9. return false;
  10. }
  11. }
  12. public int arrangeCoins(int n) {
  13. if(n==0){
  14. return 0;
  15. }
  16. int low=1; //min 1 row will be present
  17. int high =n;
  18.  
  19. int res =1;
  20. while(low <=high){
  21. int mid = low + (high - low) / 2;
  22.  
  23. if(check(mid,n) ==true){
  24. res=mid;
  25. low=mid+1;
  26. }
  27. else if(check(mid,n) ==false){
  28. high=mid-1;
  29. }
  30.  
  31. }
  32. return res;
  33. }
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
spoj: The program compiled successfully, but main class was not found.
      Main class should contain method: public static void main (String[] args).
stdout
Standard output is empty