From 7b95f173683f4eae7fd68c313839a678b2e1b79d Mon Sep 17 00:00:00 2001 From: Chris Chen Date: Tue, 7 Jun 2022 13:21:32 +0100 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0(0001.=E4=B8=A4=E6=95=B0?= =?UTF-8?q?=E4=B9=8B=E5=92=8C.md=EF=BC=89=EF=BC=9ADart=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0001.两数之和.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/problems/0001.两数之和.md b/problems/0001.两数之和.md index 6969c2e2..4ba92092 100644 --- a/problems/0001.两数之和.md +++ b/problems/0001.两数之和.md @@ -317,6 +317,20 @@ public class Solution { } ``` +Dart: +```dart +List twoSum(List nums, int target) { + var tmp = []; + for (var i = 0; i < nums.length; i++) { + var rest = target - nums[i]; + if(tmp.contains(rest)){ + return [tmp.indexOf(rest), i]; + } + tmp.add(nums[i]); + } + return [0 , 0]; +} +``` -----------------------