[LeetCode] Objective C — Reverse a NSString

Words
62
Reading
1 min
Listen
Play
10y

[LeetCode: reverse a string] (https://leetcode.com/problems/reverse-string/)

NSString* reverseString(NSString *originalString)
{
  // use a new string to append the chars from the old one
  NSString *newString = @"";
  for (int i = originalString.length-1; i >-1; i--) {
    // get the substirng to append
    NSString *charString = [originalString substringWithRange:NSMakeRange(i,1)];
    // append to the new string
    newString = [NSString stringWithFormat:@"%@%@", newString,charString];
  }
  return newString
}
[LeetCode] Objective C — Reverse a NSString | Ecency