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

做生存分析的网站有哪些网站设计与制作教程

做生存分析的网站有哪些,网站设计与制作教程,网站加入悬浮客服,交互网站怎么做的题目 题目链接: https://www.nowcoder.com/practice/5dfded165916435d9defb053c63f1e84 思路 双向链表map最新的数据放头结点,尾节点放最老的数据,没次移除尾巴节点本地考察链表的新增,删除,移动节点参考答案Java im…

题目

在这里插入图片描述
在这里插入图片描述
题目链接:
https://www.nowcoder.com/practice/5dfded165916435d9defb053c63f1e84

思路

	双向链表+map最新的数据放头结点,尾节点放最老的数据,没次移除尾巴节点本地考察链表的新增,删除,移动节点

参考答案Java

import java.util.*;public class Solution {Map<Integer, Node> cache = new HashMap<>();Node start, end;int cap = 0;public Solution(int capacity) {// write code herecap = capacity;}public int get(int key) {//key对应节点移动到头部,成为头节点if (!cache.containsKey(key)) return -1;Node cur = cache.get(key);int v = cur.data;Node next = cur.next;Node prev = cur.prev;if (next != null && prev != null) { //cur 要变成头结点next.prev = prev;prev.next = next;if (next.next == null) { //这里似乎可以不要end = next;}cur.next = start;start.prev = cur;start = cur;} else if (next != null) { //说明cur是头结点,不管了} else if (prev != null) { //自己是尾结点prev.next = null; //自己的prev要成为尾巴,prev.next设置为nullcur.next = start;start.prev = cur;start = cur;end = prev; //尾巴修改为自己的前一个节点}return v;}public void set(int key, int value) {if (cache.containsKey(key)) {cache.get(key).data = value;cache.put(key, cache.get(key));get(key); //使用一次,移动到头部} else {Node node = new Node(key, value);if (cap == 1) { //容量为1时特殊处理start = end = node;cache.clear();cache.put(key, node);return;}int size = cache.size();if (start == null) {start = node;end = node;cache.put(key, node);} else if (size < cap) { //不需要移除尾节点,直接修改头部node.next = start;start.prev = node;start = node;cache.put(key, node);} else {
//                        System.out.println();
//                        System.out.println(key+" == "+value);
//                        System.out.println();Node last = end;Node lastprev = last.prev;end = lastprev; //设置新的尾节点cache.remove(last.key);end.next = null;last = null;node.next = start;start.prev = node;start = node; //设置新的头结点cache.put(key, node);}//show(start);}}static class Node {int key;int data;Node prev;Node next;public Node(int k, int d) {key = k;data = d;}}public void show(Node root) { //帮助打印的,本答案可以不需要System.out.println("");Node t = root;Set<Integer> s = new HashSet<>();while (t != null) {System.out.print(t.key + "=>" + t.data + "   ");t = t.next;//if(s.contains(t.data)) break;}System.out.println("");}}/*** Your Solution object will be instantiated and called as such:* Solution solution = new Solution(capacity);* int output = solution.get(key);* solution.set(key,value);*/

本答案在lintcode 上相同题目没有通过全部测试用例
https://www.lintcode.com/problem/134/
后期找到原因后再修改本答案

http://www.yidumall.com/news/64350.html

相关文章:

  • 网站seo工程师怎么做精准营销名词解释
  • cms 企业网站管理系统新闻热点
  • 做网站的zk啥湛江seo
  • 上海专业做网站兰州seo快速优化报价
  • 深圳企业网站建设标准市场调研的方法
  • 做安居客网站需要什么浏览器百度风云搜索榜
  • 青岛 外语网站建设杭州搜索推广公司
  • 建设b2c商城网站定注册百度账号
  • 网页网站banner图片怎么做湖南正规seo公司
  • 淘宝上做网站的靠谱吗啥都能看的浏览器
  • 厦门建设局网站技227司学校seo查询优化
  • 管局审核一定要能打开网站上海今天发生的重大新闻
  • 广告设计接单网站江阴网站优化公司
  • 漳州做网站六六六博大a优手机怎么搭建网站
  • 做图网站电脑培训学校能学什么
  • wordpress 知乎模板郑州seo技术顾问
  • 成都市建设工程施工安监站网站成都网站建设方案推广
  • 合肥设计网站公司橘子seo
  • 成都平台网站建设公司推广营销平台
  • 网站建设开发票开什么品名提高工作效率的方法
  • p2p金融网站建设宁波seo优化
  • 国外网站做任务套利360站长平台链接提交
  • 高端建站网站的网站seo诊断分析
  • 宜昌网站推广网络推广竞价是什么
  • 动态网站上的查询怎么做如何进行市场推广
  • 宣城网站开发网络公司济南做seo排名
  • 三牛网站建设seo优化是指
  • 上海网站推广 优帮云郑州做网站推广资讯
  • 免费微网站与公众号平台对接近10天的时政新闻
  • 响应式布局网站案例网址怎么推广