I am trying the LeetCode 2-Sum problem and I am trying the following code:
var h = HashMap<Int, Int>()
var a = IntArray(2)
...few lines down...
a[1] = h.get(nums[i])
And I get an error that says error: smart cast to 'Int' is impossible, because 'h.get(nums[i])' is a complex expression
And I try to remedy this by modifying the first line of the code to be:
var h = HashMap<Int, Int>()?
And then I get the following error: error: unexpected tokens (use ';' to separate expressions on the same line)
What am I doing wrong? Why is the ? not working? Thank you!