karen goh <
contact@hi5tutors.com> wrote:
Hi,
I have problem in determining to start at 0 or 1 when doing LeetCode DSA questions.
And also whether to use arrays.length -1 that kind of things as well as using 2 loops
to do the sorting and whether to start the 2nd loop at 0 or 1 and sometimes people
use the second loop to start at the first loop 0 index.
Java starts indexing with 0, so for an array like:
int arr[] = new int[1];
you'd use index 0 for the one and only element, and arr.length would be 1.
A typical loop with an index would (in Java) look like:
for (int i=0; i<arr.length; i++) {
... do something with arr[i]...;
}
although there's also:
for (int a : arr) {
... do something with a...;
}
if you only need the values, but not their respective index.
I have no idea what you mean by "LeetCode DSA", and if they have
anything to do with Java, so I don't know, what index they feel like
having for the first element of their arrays.
Hope someone can give me some guidance.
Tks.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)