title: How to remove all evens in linked list java
body: <p>How can I remove all the evens in a linked list in java? Other similar questions did not help me. I have a possible solution, but it seems too complicated. I'm not sure it even works. </p>
  
  <pre><code>public class Node {
  public int value;
  public Node next;
  public Node (int val) {
      value = val;
  }
  public Node removeNode (Node root) {
      if (root == null || (root.next == null &amp;&amp; isOdd(root.value))) {
          return null;
      }
      Node deep = root;
      while (deep.next != null) {
          deep = deep.next;
      }
      if (isOdd(deep.value)) {
          for (Node x = root; x != null; x = x.next) {
              if (isOdd(x.next.value)) {
                  x.next = x.next.next;
              }
          }
      } else {
          for (Node x = root; x.next != null; x = x.next) {
              if (isOdd(x.next.value)) {
                  x.next = x.next.next;
              }
          }
      }
      if (isOdd(root.value)) {
          root = root.next;
      }
      return root;
  }
  public boolean isOdd (int val) {
      return (val % 2 == 1);
  }
  </code></pre>
  
  <p>How can I improve this solution? </p>