标签:
1 class Solution 2 { 3 public: 4 //Insert one char from stringstream 5 Solution():index_(0) 6 { 7 for(int i=0;i<256;i++) 8 { 9 ascii[i]=-1; 10 } 11 } 12 void Insert(char ch) 13 { 14 if(ascii[ch]==-1) 15 ascii[ch]=index_; 16 else if(ascii[ch]>=0) 17 ascii[ch]=-2; 18 index_++; 19 } 20 //return the first appearence once char in current stringstream 21 char FirstAppearingOnce() 22 { 23 int minIndex=65535; 24 char ch=‘#‘; 25 for(int i=0;i<256;i++) 26 { 27 if(ascii[i]>=0&&minIndex>ascii[i]) 28 { 29 ch=(char)i; 30 minIndex=ascii[i]; 31 } 32 } 33 return ch; 34 35 } 36 private: 37 int ascii[256]; 38 int index_; 39 };
标签:
原文地址:http://www.cnblogs.com/daocaorenblog/p/5453938.html