Today was an amazing day !
For the first time ever, we got a customer at the Genius Bar ! It was somebody unexpected: Yessin. Since he isn't in our computer apps block anymore, he has free during E block. He was in the library, doing some work on his computer when all of a sudden it got stuck. He didn't know how to use the Ctrl+Alt+Delete so he came and I helped him unfreeze his computer. I was glad to finally be able to help somebody when up at the Genius Bar.
For more good news, I flew through the Arrays today! I finished more than half of them. I completed 9 problems today, and I only have 9 more left ! This is a lot faster than strings - although there are less arrays than strings. If I continue working at this pace, I should be able to finish in the next two classes ( I am assuming I won't finish 9 problems next class because they get harder and harder towards the end).
They were relatively easy, and what especially helped me today was drawing out the arrays and each int value.
The problem for today required a little bit of different thinking. I will admit, that I did search for a hint about how to solve it. But once I had the right idea in mind, I knew exactly what to do.
Here it is:
Start with 2 int arrays, a and b, of any length. Return how many of the arrays have 1 as their first element.
start1({1, 2, 3}, {1, 3}) → 2
start1({7, 2, 3}, {1}) → 1
start1({1, 2}, {}) → 1
public int start1(int[] a, int[] b) {
int counter =0;
// create a counter that starts counting at 0.
if (a.length>0 && a[0]==1)
{
counter ++;
// if nums a has the first element as 1, then increment the counter by 1.
}
if (b.length>0 && b[0]==1)
{
counter ++;
// if nums b has the first element as 1, then increment the counter by 1.
}
return counter;
// return the value of the counter.
// what we did with this was that we simply added 1 to the counter every time an array fit the
// conditions stated. This way the counter could be incremented to 1, to 2, or it would stay at 0
// if none of the arrays had 1 as their first element.
}
I hope to finish Arrays very soon.
No comments:
Post a Comment