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

高端网站建设南宁淘宝联盟做返利网站

高端网站建设南宁,淘宝联盟做返利网站,提高网站互动性,打字网站怎么做1410. HTML 实体解析器 1410. HTML 实体解析器 代码仓库地址#xff1a; https://github.com/slience-me/Leetcode 个人博客 #xff1a;https://slienceme.xyz 编写一个函数来查找字符串数组中的最长公共前缀。 如果不存在公共前缀#xff0c;返回空字符串 …1410. HTML 实体解析器 1410. HTML 实体解析器 代码仓库地址 https://github.com/slience-me/Leetcode 个人博客 https://slienceme.xyz 编写一个函数来查找字符串数组中的最长公共前缀。 如果不存在公共前缀返回空字符串 。 「HTML 实体解析器」 是一种特殊的解析器它将 HTML 代码作为输入并用字符本身替换掉所有这些特殊的字符实体。 HTML 里这些特殊字符和它们对应的字符实体包括 双引号 字符实体为 对应的字符是 。单引号 字符实体为 对应的字符是 。与符号 字符实体为 对应对的字符是 。大于号 字符实体为 对应的字符是 。小于号 字符实体为 对应的字符是 。斜线号 字符实体为 ⁄ 对应的字符是 / 。 给你输入字符串 text 请你实现一个 HTML 实体解析器返回解析器解析后的结果。 示例 1 输入text amp; is an HTML entity but ambassador; is not. 输出 is an HTML entity but ambassador; is not. 解释解析器把字符实体 amp; 用 替换示例 2 输入text and I quote: quot;...quot; 输出and I quote: \...\示例 3 输入text Stay home! Practice on Leetcode :) 输出Stay home! Practice on Leetcode :)示例 4 输入text x gt; y amp;amp; x lt; y is always false 输出x y x y is always false示例 5 输入text leetcode.comfrasl;problemsetfrasl;all 输出leetcode.com/problemset/all提示 1 text.length 10^5字符串可能包含 256 个ASCII 字符中的任意字符。 方案1暴力解 第一种纯暴力解遍历替换 class Solution { public:string entityParser(string text) {unordered_mapstring, string myMap {{quot;, \},{apos;, \},{amp;, },{gt;, },{lt;, },{frasl;, /}};for (const auto map: myMap){string searchString map.first;string replacementString map.second;size_t pos text.find(searchString); // 找到第一个匹配的位置// 循环替换所有匹配的内容while (pos ! string::npos) {text.replace(pos, searchString.length(), replacementString); // 用替换字符串替换匹配字符串pos text.find(searchString, pos replacementString.length()); // 继续找下一个匹配的位置}}return text;} };执行用时分布 744ms 击败11.76%使用 C 的用户 消耗内存分布16.37MB 击败90.20%使用 C 的用户 方案2 发现没有优化太多反而超时了 class Solution { public:string entityParser(string text) {unordered_mapstring, string myMap {{quot;, \},{apos;, \},{amp;, },{gt;, },{lt;, },{frasl;, /}};for (int i 0; i text.length(); i){string temp;if (text[i]){if (text[i1]\0 || text[i1]){continue;}int indexj i1;while (text[indexj]!;){if (indexjtext.length()){break;}temp text[indexj];indexj1;}if (indexjtext.length()){break;}temp ;;size_t index replaceStr(text, myMap, temp);if (index ! -1){i index;}} else if(text[i]\0){continue;}}return text;}size_t replaceStr(string text, unordered_mapstring, string myMap, const string temp) const {if(myMap.find(temp) ! myMap.end()){string searchString myMap.find(temp)-first;string replacementString myMap.find(temp)-second;size_t pos text.find(searchString); // 找到第一个匹配的位置// 循环替换所有匹配的内容text.replace(pos, searchString.length(), replacementString); // 用替换字符串替换匹配字符串return posreplacementString.length()-1;}return -1;} };超出时间限制 测试用例通过了但耗时太长。 方案3 最后的优化 class Solution { public:string entityParser(string text) {string result ;int i 0;int n text.length();while (i n) {if (text[i] ) {if (text.substr(i, 6) quot;) {result \;i 6;} else if (text.substr(i, 6) apos;) {result ;i 6;} else if (text.substr(i, 5) amp;) {result ;i 5;} else if (text.substr(i, 4) gt;) {result ;i 4;} else if (text.substr(i, 4) lt;) {result ;i 4;} else if (text.substr(i, 7) frasl;) {result /;i 7;} else {result text[i];i;}} else {result text[i];i;}}return result;} };执行用时分布 68ms 击败80.39%使用 C 的用户 消耗内存分布 18.54MB 击败35.29%使用 C 的用户
http://www.zqtcl.cn/news/97927/

相关文章:

  • 展台设计网站都有哪些拓者设计吧手机版
  • 河南省级建设主管部门网站免费推广平台哪个好
  • wordpress禁止自动升级seo实战密码怎么样
  • 福永网站建设公司如何利用个人nas做网站
  • 北京网站seo外包wordpress心情
  • 租用服务器一般是谁帮助维护网站安全网站如何看是哪家公司做的
  • 戴尔网站建设的特点开创者wordpress素材
  • 网站假设公司排名不用囤货
  • 有关网站建设合同织梦珠宝网站模板
  • 月牙河做网站公司电商网站开发成本
  • iis7建立网站注册公司地址虚拟地址怎么申请
  • 响应式网站开发的想要去国外网站买东西怎么做
  • 网站建设开发有什么好处百度网盘0基础网站开发教程
  • 桂林整站优化青岛网站制作哪里有
  • 织梦cms手机网站源码天天想你视频免费观看西瓜
  • 怎么做网站弄网盟邯郸超速云_网站建设
  • 桂阳做网站的软件定制开发外包wordpress电子商务插件
  • 10有免费建网站那些公司做网站比较厉害
  • 网站关键词优化推广旅游类网站开发开题报告范文
  • 官方网站营销拟在建项目信息网官网
  • 沈阳做微信和网站的公司湛江网站建设公司哪家好
  • 网站 开发逻辑电话销售电销系统
  • 有哪些做兼职的设计网站有哪些工作可以用asp做哪些网站
  • 装修网站推广方案东莞网站建设0086
  • 知名营销网站开发高端网站建设如何收费
  • 佛山网站建设邓先生沈阳做网站找黑酷科技
  • 网站建设 排名下拉请教个人主页网站怎么做啊
  • 揭阳网站制作教程安阳seo公司
  • 网站运营管理教材wordpress 评论框插件
  • 免费做手机网站有哪些网页怎么制作链接