Skip to main content

Command Palette

Search for a command to run...

Separate the Digits in an Array

Published
1 min read
Separate the Digits in an Array
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

Given an array of positive integers nums, return an array answer that consists of the digits of each integer in nums after separating them in the same order they appear in nums.

To separate the digits of an integer is to get all the digits it has in the same order.

  • For example, for the integer 10921, the separation of its digits is [1,0,9,2,1].

LeetCode Problem - 2553

class Solution {
    public int[] separateDigits(int[] nums) {
        // Create a StringBuilder to concatenate all the digits
        StringBuilder sb = new StringBuilder();

        // Concatenate each number in the array to the StringBuilder
        for(int num : nums){
            sb.append(num);
        }

        // Convert the StringBuilder to a String
        String newStr = sb.toString();

        // Create an integer array to store the separated digits
        int[] result = new int[newStr.length()];

        // Iterate through each character in the string
        for(int i=0; i<newStr.length(); i++){
            // Convert the character to its numeric value and store it in the result array
            result[i] = Character.getNumericValue(newStr.charAt(i));
        }

        // Return the array containing separated digits
        return result;
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.