Remove all elements from a linked list of integers that have value val.
Example
Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6
Return: 1 --> 2 --> 3 --> 4 --> 5
<Solution>Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6
Return: 1 --> 2 --> 3 --> 4 --> 5
這題不困難,就是歷遍然後移除
有兩種寫法,iterative 和 recusive
iterative 如下
C++
Java
kotlin
recursive 如下
C++
Java
kotlin
沒有留言:
張貼留言