Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions strings/rotate_string.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// leetcode problem : https://leetcode.com/problems/rotate-string

class Solution {
bool rotateString(String s, String goal) {
int m = s.length;
int n = goal.length;

if (m != n) return false;

for (int i = 0; i < m; i++) {
s = s.substring(1) + s[0];
if (s == goal) return true;
}
return false;
}
}

void main() {
Solution solution = Solution();

// Test case
String s = "abcde";
String goal = "cdeab";

bool result = solution.rotateString(s, goal);

print("Input:");
print("s = \"$s\"");
print("goal = \"$goal\"");
print("Output: $result");
}