We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Python Method : Create dict to store the element as key and the index+1 of p as value.
For example, [5,2,1,3,4] we can get {5:1, 2:2, 1:3, 3:4, 4:5} and use p_dict[p_dict[1]] to get the answer 4 .
It can reduce the computing of list.index().
Sequence Equation
You are viewing a single comment's thread. Return to all comments →
Python Method : Create dict to store the element as key and the index+1 of
p
as value. For example, [5,2,1,3,4] we can get {5:1, 2:2, 1:3, 3:4, 4:5} and usep_dict[p_dict[1]]
to get the answer4
. It can reduce the computing oflist.index()
.