Share my easy undertanding code in c++


  • 0
    S

    vector<string> result;
    string temp;
    string temp_const0;//存第一个
    string temp_const1;//存第二个
    int cuur;

       //得到第一组字符串 
       for (int i=0;i<digits.length();i++){
    	   if (digits[i] == '7')  
             {temp_const0+='p';
              temp_const1+='s';}
    	   else if (digits[i] == '8')  
             {temp_const0+='t';
              temp_const1+='v';}
           else if (digits[i] == '9')  
             {temp_const0+='w';
              temp_const1+='z';}
    	   else if (digits[i] != '0'&&digits[i] != '1')            
          { temp_const0+='a'+(digits[i]-'2')*3;
            temp_const1+='a'+(digits[i]-'2')*3+2;}	            
       }                 
       if (!temp_const0.empty() )
          result.push_back(temp_const0);//存第一个
      
    	
    	 //依次修改容器中已经存在的字符串
       for (int i=0;i<temp_const0.length();i++){	    
    	   cuur = result.size();//当前个数,这里size是变化的
    	   for (int j=0;j<cuur;j++){         			  
    			for (int n=1;temp_const0[i]+n<=temp_const1[i];n++)		
    			   { temp = result[j];
    			     temp[i]=temp_const0[i]+n;
    				 result.push_back(temp);	
    		     	}
    		   }
    	   }
        return result;

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.