牛客华为机试HJ11
作者:互联网
1. 问题描述
2. Solution
1、思路分析
从后往前遍历即可。
2、代码实现
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner in;
if (!"Linux".equals(System.getProperty("os.name"))) {
in = new Scanner(Paths.get("/Users/jun/Documents/Learn/JavaLearning/NowCoder/src/huawei/HJ011/input.txt"));
} else {
in = new Scanner(System.in);
}
while (in.hasNext()) {
String s = in.nextLine();
solve(s);
}
}
private static void solve(String s) {
for (int i = s.length() - 1; i >= 0; i--)
System.out.print(s.charAt(i));
}
}
3、复杂度分析
时间复杂度: O(n)
空间复杂度: O(1)
标签:HJ11,java,Scanner,复杂度,System,牛客,import,机试,String 来源: https://www.cnblogs.com/junstat/p/16070057.html