feat: opt code

This commit is contained in:
2024-01-01 15:13:55 +08:00
parent 9b18e9ed3c
commit efe4d5b155

View File

@@ -191,13 +191,13 @@ public class Main {
} }
private static byte[] string2Bytes(String str) { private static byte[] string2Bytes(String str) {
int len = str.length(); final int len = str.length();
if ((len % 2) != 0) { if ((len % 2) != 0) {
throw new RuntimeException("String format error: " + str); throw new RuntimeException("String format error: " + str);
} }
ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
String substr = new String(new char[]{str.charAt(i++), str.charAt(i)}); final String substr = new String(new char[]{str.charAt(i++), str.charAt(i)});
baos.write((byte) Integer.parseInt(substr, 16)); baos.write((byte) Integer.parseInt(substr, 16));
} }
return baos.toByteArray(); return baos.toByteArray();