929. 独特的电子邮件地址

class Solution {
public int numUniqueEmails(String[] emails) {
		HashSet<String> hs = new HashSet<String>();
		for (int i = 0; i < emails.length; i++) {
			StringBuffer temp = new StringBuffer();
			int flag = 0;
			for (int j = 0; j < emails[i].length(); j++) {
				while (emails[i].charAt(j) == '.'&&flag==0)
					j++;
				if (emails[i].charAt(j) == '+')
					while (emails[i].charAt(j) != '@') j++;
                if(emails[i].charAt(j) == '@') flag++;
				temp.append(emails[i].charAt(j));
			}
			System.out.println(temp.toString());
			hs.add(String.valueOf(temp));
		}
		return hs.size();
	}
}

class Solution {
public int numUniqueEmails(String[] emails) {
		HashSet<String> hs = new HashSet<String>();
		for (String i : emails) {
			int at = i.indexOf('@');                                     //用一些已知的方法来确定 并且划分 
			StringBuffer name = new StringBuffer("");
			for(int x = 0; x < at ; x++) {
				if(i.charAt(x)=='+')
					break;
				if(i.charAt(x)=='.')
					x++;
				name.append(i.charAt(x));
			}
			name.append(i.substring(at,i.length()));
			hs.add(String.valueOf(name));
		}
		return hs.size();
	}
}
原文地址:https://www.cnblogs.com/cznczai/p/11320981.html