当前位置: 首页 > news >正文

郑州网站建设公司排名百度小说排行

郑州网站建设公司排名,百度小说排行,org 结尾的网站注册要什么手续,wordpress制作的网页本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章…

本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。

为了方便在PC上运行调试、分享代码文件,我还建立了相关的仓库。在这一仓库中,你不仅可以看到LeetCode原题链接、题解代码、题解文章链接、同类题目归纳、通用解法总结等,还可以看到原题出现频率和相关企业等重要信息。如果有其他优选题解,还可以一同分享给他人。

由于本系列文章的内容随时可能发生更新变动,欢迎关注和收藏征服LeetCode系列文章目录一文以作备忘。

You are given a personal information string s, representing either an email address or a phone number. Return the masked personal information using the below rules.

Email address: An email address is:

  • name consisting of uppercase and lowercase English letters, followed by
  • The '@' symbol, followed by
  • The domain consisting of uppercase and lowercase English letters with a dot '.' somewhere in the middle (not the first or last character).

To mask an email:

  • The uppercase letters in the name and domain must be converted to lowercase letters.
  • The middle letters of the name (i.e., all but the first and last letters) must be replaced by 5 asterisks "*****".

Phone number: A phone number is formatted as follows:

  • The phone number contains 10-13 digits.
  • The last 10 digits make up the local number.
  • The remaining 0-3 digits, in the beginning, make up the country code.
  • Separation characters from the set {'+', '-', '(', ')', ' '} separate the above digits in some way.

To mask a phone number:

  • Remove all separation characters.
  • The masked phone number should have the form:
    • "***-***-XXXX" if the country code has 0 digits.
    • "+*-***-***-XXXX" if the country code has 1 digit.
    • "+**-***-***-XXXX" if the country code has 2 digits.
    • "+***-***-***-XXXX" if the country code has 3 digits.
  • "XXXX" is the last 4 digits of the local number.

Example 1:

Input: s = "LeetCode@LeetCode.com"
Output: "l*****e@leetcode.com"
Explanation: s is an email address.
The name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks.

Example 2:

Input: s = "AB@qq.com"
Output: "a*****b@qq.com"
Explanation: s is an email address.
The name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks.
Note that even though "ab" is 2 characters, it still must have 5 asterisks in the middle.

Example 3:

Input: s = "1(234)567-890"
Output: "***-***-7890"
Explanation: s is a phone number.
There are 10 digits, so the local number is 10 digits and the country code is 0 digits.
Thus, the resulting masked number is "***-***-7890".

Constraints:

  • s is either a valid email or a phone number.
  • If s is an email:
    • 8 <= s.length <= 40
    • s consists of uppercase and lowercase English letters and exactly one '@' symbol and '.' symbol.
  • If s is a phone number:
    • 10 <= s.length <= 20
    • s consists of digits, spaces, and the symbols '('')''-', and '+'.

题意:返回按照题目规则、隐藏个人信息后的电子邮件地址或电话号码。


解法 模拟

首先判断 sss 是邮箱还是电话号码。显然,如果 sss 中有字符 @ ,那么它是邮箱,否则它是电话号码。

如果 sss 是邮箱,我们将 sss@ 之前的部分保留第一个和最后一个字符,中间用 ***** 代替,并将整个字符串转换为小写。

如果 sss 是电话号码,我们只保留 sss 中的所有数字regex_replace 将符合匹配规则的子串替换为其他字符串。再将最后 101010 位本地号码变成 ***-***-XXXX 的形式,并判断 sss 中是否有额外的国际号码。如果有,则将国际号码之前添加 + 号并加到本地号码的最前端,具体讨论如下:

  • 如果有 101010 位数字,则加上前缀位空字符串。
  • 如果有 111111 位数字,则加上前缀 +*-
  • 如果有 121212 位数字,则不加上前缀 +**-
  • 如果有 131313 位数字,则不加上前缀 +***-
class Solution {
private:vector<string> country = {"", "+*-", "+**-", "+***-"};
public:string maskPII(string s) {size_t idx = s.find('@'); // 有就是邮箱if (idx != string::npos) {transform(s.begin(), s.end(), s.begin(), ::tolower); // 全部小写return s.substr(0, 1) + "*****" + s.substr(idx - 1);// 名字第一个字母,中间字母用*****替换,名字最后一个字母和后面的域名不变}s = regex_replace(s, regex("[^0-9]"), ""); // 非数字字符替换为空return country[s.size() - 10] + "***-***-" + s.substr(s.size() - 4);}
};

复杂度分析:

  • 时间复杂度:O(n)O(n)O(n) ,其中 nnn 是字符串的长度。
  • 空间复杂度:O(n)O(n)O(n) ,其中 nnn 是字符串的长度。
http://www.shuangfujiaoyu.com/news/3652.html

相关文章:

  • 做网站有维护费是什么费用郑州网站制作公司
  • 图做的好的网站seo哪家好
  • 网站开发入门看什么有什么推广软件
  • 杭州网站建设索q.4791857005月新冠病毒最新消息
  • 常州网站建设电子网址怎么创建
  • 企业 办公 网站模板天堂tv在线观看
  • 保定网站设计制作公司网络软件开发
  • 服装设计素材网站关键词排名怎么做上去
  • 电子商务主要就业岗位郑州网站建设优化
  • 做网站都需要买什么关键词优化排名用哪个软件比较好
  • 网站开发程序湘潭网页设计
  • 建工网校论坛魔方优化大师官网
  • java做网站主要技术百度seo可能消失
  • 没有网站没有推广如何做外贸百度推广首次开户需要多少钱
  • 免费作图软件长春seo外包
  • 昆明网站开发公司哪家好今日新闻大事件
  • 软件开发的成本构成seo项目
  • 做的网站没流量吗安顺seo
  • 备案网站出售网络营销可以做什么工作
  • 如何建立自己个人网站营销策划书格式及范文
  • asp net mvc做网站sem运营
  • 下载网站的软件什么是口碑营销
  • flash云网站广州十大营销策划公司
  • 湖北省住房和城乡建设厅门户网站跨境电商平台
  • 提高分辨率网站百度提交入口的注意事项
  • 中国建设银行福州招聘信息网站营销推广方案范文
  • 设计公司的运营模式优化设计五年级上册语文答案
  • 西安网站开发高端网站开发百度一下百度一下你知道
  • 做网站必须花钱吗西安seo排名
  • .net网站开发工具介绍线上营销手段有哪些