Skip to content

Commit df34ed3

Browse files
committed
iterative reverse string solution in dart
1 parent 4077d1f commit df34ed3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: dart/0344-reverse-string.dart

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time Complexity: O(n)
2+
// Space Complexity: O(1)
3+
4+
class Solution {
5+
void reverseString(List<String> s) {
6+
var l = 0, r = s.length - 1;
7+
while (l <= r) {
8+
var tmp = s[l];
9+
s[l] = s[r];
10+
s[r] = tmp;
11+
l += 1;
12+
r -= 1;
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)