Separate the Numbers

  • + 0 comments

    My Java Solution:

    public static void separateNumbers(String s) { // Write your code here for(int i = 1; i <= s.length()/2; i++) {

            long firstNumber = Long.parseLong(s.substring(0, i));
            long currentNumber = firstNumber;
    
            StringBuilder shot = new StringBuilder();
            shot.append(currentNumber);
    
    
            while(shot.length() < s.length()){
                currentNumber++;
                shot.append(currentNumber);
            }
    
            if(s.equals(shot.toString()))
            {
                System.out.println("YES " + firstNumber);
                return;
            }     
        }
        System.out.println("NO");
    
    }
    

    }