From e7c921900071528fda169243e862d31be2e1b36e Mon Sep 17 00:00:00 2001 From: lhhhhhhhhhhhhhh Date: Fri, 30 Sep 2022 15:57:01 +0800 Subject: [PATCH 1/3] 222 --- src/main/java/com/bytelegend/Challenge.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/bytelegend/Challenge.java b/src/main/java/com/bytelegend/Challenge.java index 5d40ff9..59b9ddf 100644 --- a/src/main/java/com/bytelegend/Challenge.java +++ b/src/main/java/com/bytelegend/Challenge.java @@ -1,7 +1,5 @@ package com.bytelegend; -import java.util.Arrays; - public class Challenge { /** * Given an array containing any objects `Object[]`, convert it to `int[]` array. The objects @@ -22,13 +20,13 @@ public static int[] convert(Object[] objects) { ret[i] = ((Number) o).intValue(); } if (o instanceof CharSequence) { - int intnum = 0; + int val = 0; CharSequence charSequence = (CharSequence) o; for (int j = 0; j < charSequence.length(); j++) { int d = charSequence.charAt(j) - '0'; - intnum = intnum * 10 + d; + val = val * 10 + d; } - ret[i] = intnum; + ret[i] = val; } } return ret; From 63d155d09b45ea70224e7a9584ffc2f6d88ab039 Mon Sep 17 00:00:00 2001 From: lhhhhhhhhhhhhhh Date: Fri, 30 Sep 2022 16:05:07 +0800 Subject: [PATCH 2/3] 333 --- src/main/java/com/bytelegend/Challenge.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/bytelegend/Challenge.java b/src/main/java/com/bytelegend/Challenge.java index 59b9ddf..79ff267 100644 --- a/src/main/java/com/bytelegend/Challenge.java +++ b/src/main/java/com/bytelegend/Challenge.java @@ -22,10 +22,17 @@ public static int[] convert(Object[] objects) { if (o instanceof CharSequence) { int val = 0; CharSequence charSequence = (CharSequence) o; + boolean minus = false; for (int j = 0; j < charSequence.length(); j++) { + if(charSequence.charAt(j) == '-'){ + minus = true; + } int d = charSequence.charAt(j) - '0'; val = val * 10 + d; } + if(minus) { + val *= -1; + } ret[i] = val; } } From e5d7e74d6d834c7888c7deeade3b0a2a482b75c9 Mon Sep 17 00:00:00 2001 From: lhhhhhhhhhhhhhh Date: Fri, 30 Sep 2022 16:15:27 +0800 Subject: [PATCH 3/3] 123 --- src/main/java/com/bytelegend/Challenge.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/bytelegend/Challenge.java b/src/main/java/com/bytelegend/Challenge.java index 79ff267..19a08fe 100644 --- a/src/main/java/com/bytelegend/Challenge.java +++ b/src/main/java/com/bytelegend/Challenge.java @@ -26,6 +26,7 @@ public static int[] convert(Object[] objects) { for (int j = 0; j < charSequence.length(); j++) { if(charSequence.charAt(j) == '-'){ minus = true; + continue; } int d = charSequence.charAt(j) - '0'; val = val * 10 + d;