Unless does not work in ruby


  • 0
    P
    def delete_node(node)
       next_node = node.next
       if next_node != nil
           node.val = next_node.val
           node.next = next_node.next
       end
    end
    
    def delete_node(node)
        next_node = node.next
        unless next_node
            node.val = next_node.val
            node.next = next_node.next
        end
    end
    

    The second answer will not ac?


  • 0

    It works as it should, it's just wrong of you to use it there like that. Use if instead.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.