Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39829 > unrolled thread
| Started by | karen goh <contact@hi5tutors.com> |
|---|---|
| First post | 2022-10-20 09:35 -0700 |
| Last post | 2022-11-03 12:52 -0700 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
how do you determine whether to start at 0 or 1 ? karen goh <contact@hi5tutors.com> - 2022-10-20 09:35 -0700
Re: how do you determine whether to start at 0 or 1 ? Andreas Leitgeb <avl@logic.at> - 2022-11-03 17:49 +0000
Re: how do you determine whether to start at 0 or 1 ? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2022-11-03 12:52 -0700
| From | karen goh <contact@hi5tutors.com> |
|---|---|
| Date | 2022-10-20 09:35 -0700 |
| Subject | how do you determine whether to start at 0 or 1 ? |
| Message-ID | <f79712ee-8e36-44e6-97dd-00b271558671n@googlegroups.com> |
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. Till now because of this, I can't really confidently do DSA test. Hope someone can give me some guidance. Tks.
[toc] | [next] | [standalone]
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2022-11-03 17:49 +0000 |
| Message-ID | <slrntm7vog.1qde.avl@logic.at> |
| In reply to | #39829 |
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.
[toc] | [prev] | [next] | [standalone]
| From | "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> |
|---|---|
| Date | 2022-11-03 12:52 -0700 |
| Message-ID | <7276c6f6-4231-4602-9a36-7d84688400a5n@googlegroups.com> |
| In reply to | #39832 |
> 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. Apparently LeetCode is a code training web site and DSA is a test they offer for data structures and algorithms. The basic array[] variables are all zero based. Some utility object classes are one based. Indexes for instance in java.sql.PreparedStatement are one based. When it comes to objects, if there's any question, the answer should be in the javadocs.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web