标签:
1 class Different 2 { 3 4 bool quick_check(string &str, int low, int high) 5 { 6 int first = low, last = high; 7 char key = str[first]; 8 9 if(low >= high) 10 { 11 return true; 12 } 13 14 while(first < last) 15 { 16 while(first < last && str[last] >= key) 17 { 18 last--; 19 } 20 21 str[first] = str[last]; 22 while(first < last && str[first] <= key) 23 { 24 first++; 25 } 26 str[last] = str[first]; 27 } 28 29 str[first] = key; 30 if(first > low && str[first] == str[first - 1]) 31 { 32 return false; 33 } 34 35 if(first < high && str[first] == str[first + 1]) 36 { 37 return false; 38 } 39 return quick_check(str, low, first - 1) && quick_check(str, first + 1, high); 40 } 41 42 public: 43 bool checkDifferent(string iniString) 44 { 45 // write code here 46 return quick_check(iniString, 0, iniString.size() - 1); 47 48 } 49 };
标签:
原文地址:http://www.cnblogs.com/gxcdream/p/4912277.html