码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode-917 Reverse Only Letters(仅仅反转字母)

时间:2018-10-09 20:01:34      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:int   +=   public   style   leetcode   tco   isa   color   seo   

 1 class Solution
 2 {
 3     public:
 4         string reverseOnlyLetters(string S)
 5         {
 6             string onlyLetter;
 7             for(auto c:S)
 8             {
 9                 if(isalpha(c))
10                     onlyLetter += c;
11             }
12             reverse(onlyLetter.begin(),onlyLetter.end());
13             for(int i = 0,j = 0;i < S.size();i ++)
14             {
15                 if(isalpha(S[i]))
16                 {
17                     S[i] = onlyLetter[j++];
18                 }
19             }
20             return S;
21         }
22 };

 

Leetcode-917 Reverse Only Letters(仅仅反转字母)

标签:int   +=   public   style   leetcode   tco   isa   color   seo   

原文地址:https://www.cnblogs.com/Asurudo/p/9762265.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!