result = [] for i, v in enumerate(nums): result.append(nums[v]) return result
@JJ-nv5hs7 ай бұрын
I was so close to this solution, i literally only forgot the [v] part. thank you for helping me with this.
@jagggyjazz8010 Жыл бұрын
Bruh where is O(1) solution
@amroulouay6819 Жыл бұрын
class Solution: def build_array(nums): n = len(nums) for i, num in enumerate(nums): original_val = num % n new_val = nums[num] % n nums[i] = new_val * n + original_val for i in range(n): nums[i] //= n return nums
@147-dhanush8 Жыл бұрын
explain what is [ ans.append(value) ] means
@MrSaurus Жыл бұрын
That just adds each value to the ans array
@abhisheksurela28812 жыл бұрын
I don't understand the question, or I would say the question is not clear
@MKYEuphoria2 жыл бұрын
I agree. I felt like crying doing this challenge
@anonymoustv86042 жыл бұрын
Thanks for the explanation!
@rtr84633 жыл бұрын
Thank you so much
@nijatabiyev13163 жыл бұрын
thanks for the all leetcode python solutions
@mohammad_butt3 жыл бұрын
At 2:22 I meant "for" loop, not "while" loop.
@mohammad_butt3 жыл бұрын
Why we recalculate the length inside the while loop? Suppose the num array has 9 elements and we just removed an element, index will try to increment all the way to 9, but there are only 8 elements. So not decrementing length will go out of bound leading to "list index out of range" error. Alternatively, we can replace "while i < length" with "while i < len(nums) - 1". This way we wont have to manually recalculate the length.