+ 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)??
2 ответов
+ 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)
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