Skip to content

Tag: linked-list

peek and element in Java’s LinkedList

What is the difference between peek and element in Java’s LinkedList? Here is what the Oracle Java Documentation page describes them to be, but they do not explain the difference. public E peek() Retrieves, but does not remove, the head (first element) of this list. Specified by: peek in interface Deque<E> Specified by: peek in interface Queue<E> Returns: the head

Couldn’t implement binary search on linked list

i am a cse student who takes data structures course. Trying to implement binary search algorithm to my SinglyLinkedList class, somehow i’ve failed. Could you check it what’s wrong please ? The related method; I’ve debugged and it just enters the loops this side: else if(temp.getElement() > target) All class for better understanding; And the main method; It returns; Answer

Adding two linked lists in java solution results in time limit exceeded

the problem on leetcode: https://leetcode.com/problems/add-two-numbers/ My solution results in time limit exceeded and I cannot understand what’s wrong with my code: Answer It looks like you are never resetting the carry (c) back to 0. Therefore, once you set it to a non-zero value, the loop will never end. You should reset it to 0 at the start of each