diff --git a/problems/0027.移除元素.md b/problems/0027.移除元素.md index cb342586..5f681c5f 100644 --- a/problems/0027.移除元素.md +++ b/problems/0027.移除元素.md @@ -476,6 +476,32 @@ public class Solution { } ``` +###Dart: +```dart +int removeElement(List nums, int val) { + //相向双指针法 + var left = 0; + var right = nums.length - 1; + while (left <= right) { + //寻找左侧的val,将其被右侧非val覆盖 + if (nums[left] == val) { + while (nums[right] == val&&left<=right) { + right--; + if (right < 0) { + return 0; + } + } + nums[left] = nums[right--]; + } else { + left++; + } + } + //覆盖后可以将0至left部分视为所需部分 + return left; +} + +``` +