[LeetCode] Objective C — Reverse a NSString

in #programming8 years ago

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

Congratulations @nbfuhao! You have received a personal award!

1 Year on Steemit
Click on the badge to view your own Board of Honor on SteemitBoard.

Upvote this notificationto to help all Steemit users. Learn why here!

Congratulations @nbfuhao! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

Click here to view your Board

Vote for @Steemitboard as a witness and get one more award and increased upvotes!

Congratulations @nbfuhao! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 3 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Use your witness votes and get the Community Badge
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.18
TRX 0.15
JST 0.029
BTC 63193.07
ETH 2456.90
USDT 1.00
SBD 2.67