[leetcode] 929. Unique Email Addresses (easy)

统计有几种邮箱地址。

邮箱名类型:[email protected]

规则:1. local中出现"."的,忽略。 a.bc=abc

   2. local中出现"+"的,+以及之后的local全部忽略。 a+bc=a

思路:

利用set存,水题没啥好说的

Runtime: 20 ms, faster than 96.66% of C++ online submissions for Unique Email Addresses.

class Solution
{
public:
  int numUniqueEmails(vector<string> &emails)
  {
    set<string> aset;
    for (string s : emails)
    {
      bool local = true;
      bool hasPlus = false;
      string temp="";
      for (char c : s)
      {
        if (c == ‘@‘)
          local = false;
        if (c == ‘+‘ && local)
          hasPlus = true;
        if ((c == ‘.‘ || hasPlus) && local)
          continue;
        temp.push_back(c);
      }
      aset.insert(temp);
    }
    return aset.size();
  }
};

原文地址:https://www.cnblogs.com/ruoh3kou/p/10037376.html

时间: 2024-10-09 22:10:31

[leetcode] 929. Unique Email Addresses (easy)的相关文章

[LeetCode] 929. Unique Email Addresses 独特的邮件地址

Every email consists of a local name and a domain name, separated by the @ sign. For example, in?[email protected],?alice?is the local name, and?leetcode.com?is the domain name. Besides lowercase letters, these emails may contain?'.'s or?'+'s. If you

LeetCode 929 Unique Email Addresses 解题报告

题目要求 Every email consists of a local name and a domain name, separated by the @ sign. For example, in [email protected], alice is the local name, and leetcode.com is the domain name. If you add periods ('.') between some characters in the local name 

929. Unique Email Addresses

Algorithm 做一个 leetcode 的算法题 Unique Email Addresses https://leetcode.com/problems/unique-email-addresses/ 1)problem 929. Unique Email Addresses Every email consists of a local name and a domain name, separated by the @ sign. For example, in [email pro

【leetcode】929. Unique Email Addresses

题目如下: Every email consists of a local name and a domain name, separated by the @ sign. For example, in [email protected], alice is the local name, and leetcode.com is the domain name. Besides lowercase letters, these emails may contain '.'s or '+'s.

LeetCode - Unique Email Addresses

Every email consists of a local name and a domain name, separated by the @ sign. For example, in [email protected], alice is the local name, and leetcode.com is the domain name. Besides lowercase letters, these emails may contain '.'s or '+'s. If you

[Swift Weekly Contest 108]LeetCode929. 独特的电子邮件地址 | Unique Email Addresses

Every email consists of a local name and a domain name, separated by the @ sign. For example, in [email protected], alice is the local name, and leetcode.com is the domain name. Besides lowercase letters, these emails may contain '.'s or '+'s. If you

Leetcode-929 Unique Email Addresses(独特的电子邮件地址)

1 class Solution 2 { 3 public: 4 int numUniqueEmails(vector<string>& emails) 5 { 6 for(int i = 0;i < emails.size();i ++) 7 { 8 for(int j = 0;j < emails[i].size();j ++) 9 { 10 if(emails[i][j]=='@') 11 { 12 for(int k = 0;k < j;k ++) 13 {

LeetCode 804. Unique Morse Code Words

804. Unique Morse Code Words International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to &

LeetCode --- 62. Unique Paths

题目链接:Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (ma