nbfuhao avatar

[LeetCode] Objective C — Reverse a NSString

nbfuhao

Published: 06 Mar 2017 › Updated: 06 Mar 2017[LeetCode] Objective C — Reverse a NSString

[LeetCode] Objective C — Reverse a NSString

[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
}

Leave [LeetCode] Objective C — Reverse a NSString to:

Written by

Software Engineer, writing Swift and Objective codes

Read more #programming posts


Best Posts From nbfuhao

We have not curated any of nbfuhao's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From nbfuhao