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

苏州建设网站价格建设彩票网站制作

苏州建设网站价格,建设彩票网站制作,广告公司名字免费起名大全,文档流程做网站本文属于「征服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.yayakq.cn/news/625331/

相关文章:

  • 怎么做网站申请广告合肥生态丽景网站建设
  • 手机免费自建网站网站基本模板
  • 上门做美容的网站网站建设上机课
  • 能自己做二次元人物的网站全球网站排行
  • 网站设计编辑免费注册163免费邮箱申请
  • 如何做自适应网站元器件网站开发客户
  • 电子商务网站建设与维护论文网站建设公司哪家好
  • 做网站的公司主要工作网络热词缩写
  • 做网站租什么服务器企业网站建设在国内现状
  • 建设一个连接的网站wordpress添加百度地图吗
  • 国家排污许可网站台账怎么做大连网站制作信ls15227
  • 湖州网站制作公司江苏自助建站平台
  • 西安市建网站青海网站开发公司
  • 有什么手机网站公司部门聚餐计入什么科目
  • 英铭科技做网站和设计制作更专业中国电子商务企业
  • 自己做的网站打开慢北京市地铁建设公司网站
  • 网站平台建设制度家装公司网站开发方案
  • 网站降权怎么做联想网站建设摘要
  • php网站开发示例做电商在什么网站
  • 和嗲囡囡和做的网站沈阳网站设计营销型
  • 长网页网站专业展示设计网站
  • 早厦门构网站建设巨耀网站建设公司
  • 服装网站怎么做的深圳做宣传网站的公司
  • 石家庄网站建设网站建设网站开发运营公司绩效提成方案
  • 网站建设结构企业网站的网页设计
  • 抖音网站建设哪家好订阅号可以做网站么
  • 建设通网站有法律下载应用的app
  • 网站改版要重新备案想学习做网站
  • 网页制作软件coreldrawseo如何提升排名收录
  • 建筑兼职网站软件界面设计图