题目
简单,从字符串中删除空格,然后返回结果字符串。
测试用例:
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class SolutionTest {
@Test public void testSomething() {
assertEquals("8j8mBliB8gimjB8B8jlB", Kata.noSpace("8 j 8 mBliB8g imjB8B8 jl B"));
assertEquals("88Bifk8hB8BB8BBBB888chl8BhBfd", Kata.noSpace("8 8 Bi fk8h B 8 BB8B B B B888 c hl8 BhB fd"));
assertEquals("8aaaaaddddr", Kata.noSpace("8aaaaa dddd r "));
assertEquals("jfBmgklf8hg88lbe8", Kata.noSpace("jfBm gk lf8hg 88lbe8 "));
assertEquals("8jaam", Kata.noSpace("8j aam"));
}
}
解题
class Kata {
static String noSpace(final String x) {
return x.replace(" ", "");
}
}
后记
大家答案都差不多。
网友评论