zoukankan      html  css  js  c++  java
  • LeetCode 929. Unique Email Addresses (独特的电子邮件地址)

    题目标签:String

      题目说明 有两个规则针对于 local name。 所以先把local name 和 domain name 分开。

      两个规则是:

        rule 1:'.' 会被去除。 (利用replace 把 '.' 换成 '')

        rule 2:'+' 之后的所有东西都会被 去除。(利用substring 把 '+' 之后的去除)

    Java Solution:

    Runtime beats 34.05% 

    完成日期:12/08/2018

    关键点:substring 和 replace

    class Solution 
    {
        public int numUniqueEmails(String[] emails) 
        {
            Set<String> set = new HashSet<>();
            
            for(String email : emails)
            {
                String editedEmail = editEmail(email);
                
                set.add(editedEmail);
                
            }
            
            return set.size();
        }
        
        private String editEmail(String email)
        {
            int index = email.indexOf('@');
            String str_1 = email.substring(0, index);
            String str_2 = email.substring(index);
            
            if(str_1.contains("+"))
                str_1 = str_1.substring(0, str_1.indexOf('+'));
            
            str_1 = str_1.replace(".", "");        
    
            return str_1 + str_2;
        }
    }

    参考资料:N/A

    LeetCode 题目列表 - LeetCode Questions List

    题目来源:https://leetcode.com/

  • 相关阅读:
    K8S-安全机制
    K8S-Service
    K8S-Pod资源管理
    K8S-kubelet启动过程
    每日进度
    每日进度
    每日进度
    每日进度
    每日进度
    归纳及计划
  • 原文地址:https://www.cnblogs.com/jimmycheng/p/10089995.html
Copyright © 2011-2022 走看看