Regarding finding the middle element of linked list

后端 未结 5 1618
轮回少年
轮回少年 2021-02-04 20:19

I am following the below approach to calculate the middle element from the linked list , but I want is there any built in method or any other approach which can als

5条回答
  •  独厮守ぢ
    2021-02-04 21:05

    I would recommend using the Java built in

    LinkedList
    
    
    

    It gives you all the functionality you need like getting the length: list.size(), and the middle object:

    list.get((list.size())/2);
    

    提交回复
    热议问题