oday
11/06/2020, 10:59 AMin
cause the runtime of the program to become as if it were 2 for loops O(n2)?Tobias Berger
11/06/2020, 11:17 AMin
in this case is just syntactic sugar for contains
, so line 7 is the same as if (values.contains(difference)) {
. What happens inside of the contains-Function depends on the map implementation (here a LinkedHashMap)oday
11/06/2020, 12:09 PModay
11/06/2020, 12:09 PMnanodeath
11/06/2020, 5:23 PMcontains
and .get(...) != null
can be different because values can be null. but because it's Kotlin, they're basically equivalentnanodeath
11/06/2020, 5:23 PMto
instead of Pair
...usually looks nicernanodeath
11/06/2020, 5:24 PMvalues[difference]?.let { return index to it }
(or something like that), as that'll save you the trouble of doing the lookup in values
twice