博客
关于我
LeetCode.811 Subdomain Visit Count
阅读量:700 次
发布时间:2019-03-17

本文共 743 字,大约阅读时间需要 2 分钟。

解析题目并提出解决方案

题目要求我们根据给定的count-paired domain列表,生成包含每个子域名及总访问次数的count-paired domain列表。每个输出项应包含访问次数后跟相应的子域名,顺序任意。

解决方法:

  • 理解count-paired domain:每个count-paired domain由一个访问次数(整数)和一个域名组成。例如,"9001 discuss.leetcode.com"表示访问"discuss.leetcode.com"的总次数为9001次。

  • 拆分域名:将每个域名按'.'分割,得到其各个子域名。例如,"discuss.leetcode.com"拆分为["discuss", "leetcode", "com"]。

  • 统计访问次数:对于每个拆分后的子域名,记录其总访问次数。同一个子域名若出现多次,次数应进行相加。

  • 生成结果:将统计结果的每个子域名及其对应的访问次数组合成count-paired domain格式,例如"9001 discuss.leetcode.com"。

  • 实现步骤:

  • 初始化一个Java HashMap记录子域名及访问次数。
  • 遍历输入列表,为每个count-paired domain:
    • 提取访问次数和域名。
    • 拆分域名并处理每个子域名,更新对应的访问次数。
    • 特别处理顶级域名及直接子域名。
  • 收集所有子域名及其访问次数,按格式生成结果列表。
  • 关键注意事项:

    • 确保处理所有可能的子域名,包括顶级域名,避免遗漏。
    • 处理不同层级子域名时,确保每个子域名独立统计,不互相干扰。
    • 处理输入数据时要考虑到输入格式的正确性,以及域名的层级结构。

    通过以上方法,可以高效地解决问题,生成所需的count-paired domain列表。

    转载地址:http://hcjez.baihongyu.com/

    你可能感兴趣的文章
    NotImplementedError: Could not run torchvision::nms
    查看>>
    nova基于ubs机制扩展scheduler-filter
    查看>>
    Now trying to drop the old temporary tablespace, the session hangs.
    查看>>
    nowcoder—Beauty of Trees
    查看>>
    np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
    查看>>
    np.power的使用
    查看>>
    NPM 2FA双重认证的设置方法
    查看>>
    npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
    查看>>
    npm build报错Cannot find module ‘webpack‘解决方法
    查看>>
    npm ERR! ERESOLVE could not resolve报错
    查看>>
    npm ERR! fatal: unable to connect to github.com:
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
    查看>>
    npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
    查看>>
    npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
    查看>>
    npm install CERT_HAS_EXPIRED解决方法
    查看>>
    npm install digital envelope routines::unsupported解决方法
    查看>>
    npm install 卡着不动的解决方法
    查看>>
    npm install 报错 EEXIST File exists 的解决方法
    查看>>
    npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
    查看>>