+ 2

Return number of index of number

Input: Int number=123; Int index =0; Output: 1 How can I implement a method that get number and index and return the number of the index in complexity O(1)??

28th Jan 2018, 3:08 AM
Saggi Bashari
Saggi Bashari - avatar
2 Respuestas
+ 8
$("li").click(function(){ var str = $(this).index(); alert(str); }); by this you can get the number by entering the index and complexity is also O(n)
28th Jan 2018, 3:22 AM
GAWEN STEASY
GAWEN STEASY - avatar
0
this is my code: public static int getNumberByIndex(int num, int index){ num = (int) (num / Math.pow(10, index)); num = num %10; return num; } my question is how i can change the index = 0 to be index = len(number) in O(1)? thanks
28th Jan 2018, 12:19 PM
Saggi Bashari
Saggi Bashari - avatar