Пример #1
0
  private static boolean findElement(ListNode<Integer> head, ListNode<Integer> tail, int val) {
    if (head != null && head.val == val) {
      return true;
    }
    if (head == tail) {
      return head != null && head.val == val;
    }
    ListNode<Integer> mid = linkedListUtil.getMiddleNode(head, tail);

    if (mid.val == val) {
      return true;
    }
    if (mid.val < val) {
      return findElement(mid, tail, val);
    }
    return findElement(head, mid, val);
  }
Пример #2
0
 public static void main(String[] args) {
   linkedListUtil = new LinkedListUtil();
   ListNode<Integer> head = linkedListUtil.createLinkedList(9);
   System.out.println(linkedListUtil.linkedListToString(head));
   System.out.println(findElement(head, 11));
 }
Пример #3
0
 private static boolean findElement(ListNode<Integer> head, int val) {
   ListNode<Integer> tail = linkedListUtil.getTail(head);
   return findElement(head, tail, val);
 }