我得到了数字作为单词:
{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
Run Code Online (Sandbox Code Playgroud)
数字最多只有 10 个。我的任务是将给定的两个输入字符串相互比较。
当您比较两个数字时,它基本上应该起作用:
compare(1, 1) -> 0;
compare(1, 3) -> 1 < 3 as -1;
compare(5, 2) -> 5 > 2 as 1;
Run Code Online (Sandbox Code Playgroud)
像这样比较两个字符串的最佳方法是什么?
结果看起来像这样:
compare("one", "one") -> 0;
compare("one", "three") -> -1;
compare("five", "two") -> 1;
Run Code Online (Sandbox Code Playgroud)
{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
Run Code Online (Sandbox Code Playgroud)