How to solve the Codewars's Highest and Lowest
Today I try to solve the algorithm problem of codewars.
Description
In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number.
Example
-
HighAndLow(“1 2 3 4 5”) -> “5 1”
-
HighAndLow(“1 2 -3 4 5”) -> “5 -3”
-
HighAndLow(“1 9 3 4 -5”) -> “9 -5”
Code
-
split() : returns array of strings computed by splitting.
-
parseInt() : returns the integer representation of the argument.
-
Arrays.sort() : array to be sorted.
-
Integer.toString() : returns the String object representing the Integer value.
import java.util.*;
public class Kata {
public static String HighAndLow(String numbers) {
# Codewars COC 정책으로 인하여 코드 제거
return Integer.toString(intArr[intArr.length-1]) + " " + Integer.toString(intArr[0]) ;
}
}
Written on December 12, 2018