tannergooding
Unable to reset repeatCount variable to 0
so to fix this, you want to always reset the
repeatCount
before the next iteration of the for (int i = ...)
loop
but you should really rename this occurrenceCount
instead
you should consider ways you can avoid duplicating work (avoid checking characters you've already checked, you can)
you should consider if you can avoid allocating a List<char>
at all (you can)
and if you can avoid iterating the input more than once (you can)11 replies
Unable to reset repeatCount variable to 0
that is,
repeatCount
starts at 0
the first iteration you encounter c
, you increment the count by 1
this is greater than highestRepeatCount
which is 0
so you set highestRepeatCount = 1
, indexOfMostRepeated = 0
, and reset repeatCount = 0
then you encounter a
, you unnecessarily check c
again
encounter a
, increment the count by 1
this is not greater than the highest, so you don't modify repeatCount
then you encounter t
, you unnecessarily check ca
again
then you encounter t
and increment the count by 1
(making it 2
since it wasn't reset after checking a
)11 replies
Unable to reset repeatCount variable to 0
this looks like an expensive way to do the check, first of all; there are much simpler ways to handle this
you also have a bug in that you're miscounting by 1 because you're starting at
0
that is given your intent cat
will find c = 1
, a = 1
, t = 1
; so you're rather finding the occurrence count; not repeat count
the actual issue is, however, that you're getting c = 1
, a = 1
, t = 2
because repeatCount
isn't reset after a
11 replies