Contents

0 off (with.Java)

   Nov 13, 2023     0 min read

This is a post about the “zero off” problem.

We’re going to learn by solving coding test problems, reflecting on the problems we’ve solved, and exploring other ways to solve them.

Let’s start with the problem.

Problem

Given a string n_str of integers, complete the solution function so that it returns a string of zeros stripped of the first leftmost occurrence of n_str.

Example input and output
n_strresult
“0010”“10”
“854020”“854020”

My solution to the problem

class Solution {
    public String solution(String n_str) {
        String answer = String.valueOf(Integer.parseInt(n_str));
        return answer;
    }
}
Solution.

A string to integer conversion was performed to remove the first occurrence of a zero on the left side of n_str, which is composed of strings.

The integer was then converted back to a string and returned.