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

LeetCode题解之 Letter Case Permutation

时间:2018-07-14 19:29:33      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:img   问题分析   png   slow   使用   技术   oid   perm   方法   

1、题目描述

技术分享图片

2、问题分析

可以使用递归的方法解决,参考了别人的答案才写出来的。

3、代码

 1  vector<string> letterCasePermutation(string S) {
 2         vector<string> res ;
 3         recursion( S,res,0 );
 4         return res;
 5         
 6     }
 7     
 8     void recursion(string & s , vector<string> &r ,int p){
 9         if( p == s.size() ){
10             r.push_back( s );
11             return ;
12         }
13             
14         recursion( s ,r ,p+1 );
15         if( isalpha( s[p] )){
16            if( islower( s[p] ) ){
17                 s[p] += A - a;
18             }else if( isupper( s[p] ) ){
19                 s[p] += a - A;
20             }
21             recursion( s,r,p+1 ); 
22         }
23     }

 

LeetCode题解之 Letter Case Permutation

标签:img   问题分析   png   slow   使用   技术   oid   perm   方法   

原文地址:https://www.cnblogs.com/wangxiaoyong/p/9310687.html

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