I guess it's quite good in 22 minutes.
1.
Hashtable<Integer, Integer> myTable = new Hashtable<Integer, Integer>();
Instead of the Hashtable
use HashMap
, but you use it like a Set
(same key and value, so value is unused), so use a HashSet
instead. See: Differences between HashMap and Hashtable? Differences between HashMap and Hashtable?
I would use a longer variable names than
A
. Longer names would make the code more readable since readers don't have to decode the abbreviations every time and when they write/maintain the code don't have to guess which abbreviation the author uses. Furthermore, usual Java variable names are camelCase, with lowercase first letter. (See: Effective Java, 2nd edition, Item 56: Adhere to generally accepted naming conventions)myTable
could have a more descriptive name.I've removed everything which does not change
minVal
's value:
int minVal=0; ... for(int i : A){ if(i<minVal && i>0){ minVal = i; } ... }
If I'm right the condition of the if
statement is always false
. If you substitute minVal
's initial value, you get this:
i < 0 && i > 0
which is false
, so minVal
's value never can be changed.
I'd put a guard clause inside the for to get rid of the negative values and save some memory in the set:
for (int i: A) { if (i < 0) { continue; } set.add(i); }
- If you want to save some memory with big, non-repetitive input arrays you could use a
new BitSet(A.length)
.
I guess it's quite good in 22 minutes.
1.
Hashtable<Integer, Integer> myTable = new Hashtable<Integer, Integer>();
Instead of the Hashtable
use HashMap
, but you use it like a Set
(same key and value, so value is unused), so use a HashSet
instead. See: Differences between HashMap and Hashtable?
I would use a longer variable names than
A
. Longer names would make the code more readable since readers don't have to decode the abbreviations every time and when they write/maintain the code don't have to guess which abbreviation the author uses. Furthermore, usual Java variable names are camelCase, with lowercase first letter. (See: Effective Java, 2nd edition, Item 56: Adhere to generally accepted naming conventions)myTable
could have a more descriptive name.I've removed everything which does not change
minVal
's value:
int minVal=0; ... for(int i : A){ if(i<minVal && i>0){ minVal = i; } ... }
If I'm right the condition of the if
statement is always false
. If you substitute minVal
's initial value, you get this:
i < 0 && i > 0
which is false
, so minVal
's value never can be changed.
I'd put a guard clause inside the for to get rid of the negative values and save some memory in the set:
for (int i: A) { if (i < 0) { continue; } set.add(i); }
- If you want to save some memory with big, non-repetitive input arrays you could use a
new BitSet(A.length)
.
I guess it's quite good in 22 minutes.
1.
Hashtable<Integer, Integer> myTable = new Hashtable<Integer, Integer>();
Instead of the Hashtable
use HashMap
, but you use it like a Set
(same key and value, so value is unused), so use a HashSet
instead. See: Differences between HashMap and Hashtable?
I would use a longer variable names than
A
. Longer names would make the code more readable since readers don't have to decode the abbreviations every time and when they write/maintain the code don't have to guess which abbreviation the author uses. Furthermore, usual Java variable names are camelCase, with lowercase first letter. (See: Effective Java, 2nd edition, Item 56: Adhere to generally accepted naming conventions)myTable
could have a more descriptive name.I've removed everything which does not change
minVal
's value:
int minVal=0; ... for(int i : A){ if(i<minVal && i>0){ minVal = i; } ... }
If I'm right the condition of the if
statement is always false
. If you substitute minVal
's initial value, you get this:
i < 0 && i > 0
which is false
, so minVal
's value never can be changed.
I'd put a guard clause inside the for to get rid of the negative values and save some memory in the set:
for (int i: A) { if (i < 0) { continue; } set.add(i); }
- If you want to save some memory with big, non-repetitive input arrays you could use a
new BitSet(A.length)
.
I guess it's quite good in 22 minutes.
1.
Hashtable<Integer, Integer> myTable = new Hashtable<Integer, Integer>();
Instead of the Hashtable
use HashMap
, but you use it like a Set
(same key and value, so value is unused), so use a HashSet
instead. See: Differences between HashMap and Hashtable?
I would use a longer variable names than
A
. Longer names would make the code more readable since readers don't have to decode the abbreviations every time and when they write/maintain the code don't have to guess which abbreviation the author uses. Furthermore, usual Java variable names are camelCase, with lowercase first letter. (See: Effective Java, 2nd edition, Item 56: Adhere to generally accepted naming conventions)myTable
could have a more descriptive name.I've removed everything which does not change
minVal
's value:
int minVal=0; ... for(int i : A){ if(i<minVal && i>0){ minVal = i; } ... }
If I'm right the condition of the if
statement is always false
. If you substitute minVal
's initial value, you get this:
i < 0 && i > 0
which is false
, so minVal
's value never can be changed.
I'd put a guard clause inside the for to get rid of the negative values and save some memory in the set:
for (int i: A) { if (i < 0) { continue; } set.add(i); }
- If you want to save some memory with big, non-repetitive input arrays you could use a
new BitSet(A.length)
.
Hashtable<Integer, Integer> myTable = new Hashtable<Integer, Integer>();
Instead of the Hashtable
use HashMap
, but you use it like a Set
(same key and value, so value is unused), so use a HashSet
instead. See: Differences between HashMap and Hashtable?
I would use a longer variable names than
A
. Longer names would make the code more readable since readers don't have to decode the abbreviations every time and when they write/maintain the code don't have to guess which abbreviation the author uses. Furthermore, usual Java variable names are camelCase, with lowercase first letter. (See: Effective Java, 2nd edition, Item 56: Adhere to generally accepted naming conventions)myTable
could have a more descriptive name.I've removed everything which does not change
minVal
's value:
int minVal=0; ... for(int i : A){ if(i<minVal && i>0){ minVal = i; } ... }
If I'm right the condition of the if
statement is always false
. If you substitute minVal
's initial value, you get this:
i < 0 && i > 0
which is false
, so minVal
's value never can be changed.
I'd put a guard clause inside the for to get rid of the negative values and save some memory in the set:
for (int i: A) { if (i < 0) { continue; } set.add(i); }
I guess it's quite good in 22 minutes.
1.
Hashtable<Integer, Integer> myTable = new Hashtable<Integer, Integer>();
Instead of the Hashtable
use HashMap
, but you use it like a Set
(same key and value, so value is unused), so use a HashSet
instead. See: Differences between HashMap and Hashtable?
I would use a longer variable names than
A
. Longer names would make the code more readable since readers don't have to decode the abbreviations every time and when they write/maintain the code don't have to guess which abbreviation the author uses. Furthermore, usual Java variable names are camelCase, with lowercase first letter. (See: Effective Java, 2nd edition, Item 56: Adhere to generally accepted naming conventions)myTable
could have a more descriptive name.I've removed everything which does not change
minVal
's value:
int minVal=0; ... for(int i : A){ if(i<minVal && i>0){ minVal = i; } ... }
If I'm right the condition of the if
statement is always false
. If you substitute minVal
's initial value, you get this:
i < 0 && i > 0
which is false
, so minVal
's value never can be changed.
I'd put a guard clause inside the for to get rid of the negative values and save some memory in the set:
for (int i: A) { if (i < 0) { continue; } set.add(i); }
- If you want to save some memory with big, non-repetitive input arrays you could use a
new BitSet(A.length)
.
Hashtable<Integer, Integer> myTable = new Hashtable<Integer, Integer>();
Instead of the Hashtable
use HashMap
, but you use it like a Set
(same key and value, so value is unused), so use a HashSet
instead. See: Differences between HashMap and Hashtable?
I would use a longer variable names than
A
. Longer names would make the code more readable since readers don't have to decode the abbreviations every time and when they write/maintain the code don't have to guess which abbreviation the author uses. Furthermore, usual Java variable names are camelCase, with lowercase first letter. (See: Effective Java, 2nd edition, Item 56: Adhere to generally accepted naming conventions)myTable
could have a more descriptive name.I've removed everything which does not change
minVal
's value:
int minVal=0; ... for(int i : A){ if(i<minVal && i>0){ minVal = i; } ... }
If I'm right the condition of the if
statement is always false
. If you substitute minVal
's initial value, you get this:
i < 0 && i > 0
which is false
, so minVal
's value never can be changed.
I'd put a guard clause inside the for to get rid of the negative values and save some memory in the set:
for (int i: A) { if (i < 0) { continue; } set.add(i); }
Hashtable<Integer, Integer> myTable = new Hashtable<Integer, Integer>();
Instead of the Hashtable
use HashMap
, but you use it like a Set
(same key and value, so value is unused), so use a HashSet
instead. See: Differences between HashMap and Hashtable?
I would use a longer variable names than
A
. Longer names would make the code more readable since readers don't have to decode the abbreviations every time and when they write/maintain the code don't have to guess which abbreviation the author uses. Furthermore, usual Java variable names are camelCase, with lowercase first letter. (See: Effective Java, 2nd edition, Item 56: Adhere to generally accepted naming conventions)myTable
could have a more descriptive name.
Hashtable<Integer, Integer> myTable = new Hashtable<Integer, Integer>();
Instead of the Hashtable
use HashMap
, but you use it like a Set
(same key and value, so value is unused), so use a HashSet
instead. See: Differences between HashMap and Hashtable?
I would use a longer variable names than
A
. Longer names would make the code more readable since readers don't have to decode the abbreviations every time and when they write/maintain the code don't have to guess which abbreviation the author uses. Furthermore, usual Java variable names are camelCase, with lowercase first letter. (See: Effective Java, 2nd edition, Item 56: Adhere to generally accepted naming conventions)myTable
could have a more descriptive name.I've removed everything which does not change
minVal
's value:
int minVal=0; ... for(int i : A){ if(i<minVal && i>0){ minVal = i; } ... }
If I'm right the condition of the if
statement is always false
. If you substitute minVal
's initial value, you get this:
i < 0 && i > 0
which is false
, so minVal
's value never can be changed.
I'd put a guard clause inside the for to get rid of the negative values and save some memory in the set:
for (int i: A) { if (i < 0) { continue; } set.add(i); }