Middle-题目107:61. Rotate List

部署运行你感兴趣的模型镜像

题目原文:
Given a list, rotate the list to the right by k places, where k is non-negative.

For example:
Given 1->2->3->4->5->NULL and k = 2,
return 4->5->1->2->3->NULL.
题目大意:
把一个链表循环右移K位。
题目分析:
先把链表连成环(尾节点连到head上),并统计节点个数count,然后从head开始把第count-k%count个节点拆下来就行了。
源码:(language:c)

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* rotateRight(struct ListNode* head, int k) {
    if(!head || !head->next)
        return head;
    struct ListNode* end;
    int count=1;
    for(end = head; end->next; end = end->next)
        count++;
    end->next = head;
    struct ListNode *p1=head,*p2=head->next;
    for(int i=1;i<count-k%count;i++) {
        p1=p1->next;
        p2=p2->next;
    }
    p1->next = NULL;
    return p2;
}

成绩:
4ms,beats 6.02%,众数4ms,93.98%
cmershen的碎碎念:
本题有一个陷阱在于,如果直接从环上找第k个点是错误的,因为这里的k可能远大于链表长度,而对环来说移动一圈相当于没动,所以取余即可。

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

<template> <myModal :params="{title: $t('选择报警类型')}" :modalWidthSize="'middle'" :visible="visible" @submit="handleOk" @cancel="handleCancel"> <template v-slot:header><span></span></template> <template v-slot:body> <div class="alarm_type_modal"> <div class="main_content" v-if="alarmTypeList.length"> <div class="search_item"> <a-input-search @search="handleAlarmTypeSearch" :placeholder="$t('请输入报警类型名称')" /> </div> <template v-if="isShowList"> <div class="check_item"> <div class="all_check"> <a-checkbox :indeterminate="indeterminate" :checked="checkAll" @change="onCheckAllChange"> {{ $t("用电告警")}} </a-checkbox> <img class="down" @click="changeIcon" :class="{'up': expanded}" src="~@/assets/img/down.png" /> </div> <div :class="['check_group_list', expanded ? 'checkboxUp': 'checkboxDown' ]"> <a-checkbox-group v-model="checkedList" @change="onCheckChange"> <template v-for="el in alarmTypeList"> <a-checkbox v-if="el.isShow" :key="el.alarmTypeCode" :value="el.alarmTypeCode"> <span :title="$t(el.alarmTypeName)"> {{ $t(el.alarmTypeName) }} </span> </a-checkbox> </template> </a-checkbox-group> </div> </div> </template> <noData v-else /> </div> <a-space :size="64" v-else> <a-spin tip="加载中,请稍候..." /> </a-space> </div> </template> </myModal> </template> <script> import factory from '../../factory'; import noData from '@/components/tableNoData' import myModal from "@/components/scfComponents/modalComponents/modal.vue"; export default { components: { noData, myModal }, data() { return { visible: false, isShowList: true, indeterminate: false, checkAll: false, expanded: true, checkedList: [], // 所有选中项 alarmTypeList: [], // 原始数据 checkListBak: [] } }, computed: { }, watch: { }, methods: { getAlarmTypeList() { factory.getAlarmTypeList().then(res => { this.alarmTypeList = res.map(item => ({ …item, isShow: true })) || [] this.updateCheckStatus() }) }, // 打开弹窗 showModal(data) { this.visible = true this.checkedList = [...data]; this.getAlarmTypeList(); }, // 报警类型搜索 handleAlarmTypeSearch(val) { const searchTerm = val.toLowerCase().trim(); if (!searchTerm) { this.alarmTypeList.forEach(item => { item.isShow = true }) if (this.checkListBak.length) { this.checkedList = [...this.checkedList, ...this.checkListBak] } } else { this.checkListBak = this.checkedList // 搜索将之前选中数据备份 this.alarmTypeList.forEach(item => { if (item.alarmTypeName.toLowerCase().includes(searchTerm)) { item.isShow = true } else { item.isShow = false } }) this.checkedList = [] } this.updateCheckStatus() this.$forceUpdate() }, updateCheckStatus() { let alarmTypeCodes = this.alarmTypeList.filter(item => item.isShow) let checkedList = this.checkedList this.indeterminate = !!checkedList.length && checkedList.length < alarmTypeCodes.length; this.checkAll = alarmTypeCodes.length > 0 && checkedList.length === alarmTypeCodes.length; this.isShowList = alarmTypeCodes.length > 0 }, // 全选 onCheckAllChange(e) { const alarmTypeCodes = this.alarmTypeList.filter(item => item.isShow).map(el => el.alarmTypeCode) Object.assign(this, { checkedList: e.target.checked ? [...alarmTypeCodes] : [], indeterminate: false, checkAll: e.target.checked, }); }, changeIcon() { this.expanded = !this.expanded }, // 单选 onCheckChange() { this.updateCheckStatus() }, // 确定 handleOk() { this.visible = false }, // 取消 handleCancel() { this.visible = false } }, } <style lang="less" scoped> .alarm_type_modal { width: 100%; display: flex; padding: 24px; box-sizing: border-box; justify-content: center; .main_content { width: 100%; min-height: 400px; position: relative; border-radius: 8px; border: solid 1px #c5cdd6; padding: 23px 10px 10px 16px; .search_item { width: 100%; margin-bottom: 15px; } .check_item { border-radius: 4px; margin-bottom: 10px; border: 1px solid var(--split); .all_check { display: flex; padding: 10px 16px; align-items: center; justify-content: space-between; background-color: #f0f3f7; .down { width: 13px; height: 8px; transition: all 0.5s; cursor: pointer; } .up { transform: rotate(180deg); } } .check_group_list { width: 100%; overflow: hidden; transition: all 1s; .ant-checkbox-group { width: 100%; padding: 8px 0 8px 14px; .ant-checkbox-wrapper { margin: 0; width: 25%; padding: 4px; overflow: hidden; line-height: 28px; padding-left: 18px; white-space: nowrap; text-overflow: ellipsis; border-right: 1px solid #f0f3f7; &:nth-child(4n) { border-right: none; } } } } .checkboxDown { height: 0px; } .checkboxUp { min-height: 30px; } } } } </style> 代码评审 alarmTypeList数据量1800条 不可以分页优化 不可以使用虚拟列表
08-15
* { margin: 0; padding: 0; } body { font-family: "微软雅黑", Arial, sans-serif; font-size: 14px; } .banner { width: 100%; height: 300px; position: relative; } .banner img { width: 100%; height: 300px; object-fit: cover; } .layer { position: absolute; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); } .banner p { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: white; font-size: 45px; text-align: center; } .container { width: 100%; height: 50px; background: darkorange; margin-top: 2px; } .menu { width: 800px; height: 50px; margin: 0 auto; } .menu ul { display: flex; justify-content: space-around; align-items: center; } .menu ul li { list-style: none; } .menu a { text-decoration: none; color: white; padding: 15px 20px; display: block; } .menu a:hover { background: darkgreen; } .footer { width: 800px; height: 400px; margin: 20px auto; display: flex; } .left { flex: 1; background: black; position: relative; } .right { flex: 1; background: #eee; padding: 20px; } .left ul li { list-style: none; border-radius: 100%; border: 1px solid #394; position: absolute; } .sun { width: 20px; height: 20px; background: yellow; top: 185px; left: 190px; border: none; } .shui { width: 60px; height: 30px; top: 165px; left: 170px; animation: myanimation 6s linear infinite; } .shui span { width: 4px; height: 4px; background: blue; display: block; border-radius: 100%; position: absolute; left: 5px; top: 8px; } .earth { width: 130px; height: 130px; top: 130px; left: 135px; animation: myanimation 5s linear infinite; } .earth > span { width: 4px; height: 20px; background: yellow; position: absolute; left: 5px; top: 8px; } .moon { width: 2px; height: 2px; background: rgb(243, 242, 242); position: absolute; top: -4px; left: -4px; display: block; border-radius: 100%; } @keyframes myanimation { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } .btn { display: inline-block; padding: 10px 20px; background: #4d92d9; color: white; text-decoration: none; border: 2px solid #4d92d9; transition: all 0.4s; } .btn:hover { background: white; color: #4d92d9; }<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" type="text/css" href="sy2.css" /> </head> <body> <div class="banner"> <div class="img"> <img src="images/1.jpeg"> </div> <div class="layer"></div> <p></p > </div> <div class="container"> <div class="menu"> <ul> <li><a href=" ">首页</a ></li> <li><a href="#">推荐阅读</a ></li> <li><a href="#">历史故事</a ></li> <li><a href="#">代表人物</a ></li> <li><a href="#">代表人物</a ></li> <li><a href="#">体育锻炼</a ></li> <li><a href="#">学习攻略</a ></li> <li><a href="#">头脑风暴</a ></li> </ul> </div> </div> <div class="footer"> <div class="left"> <ul> <li class="sun"></li> <li class="shui"><span></span></li> <li class="jin"><span></span></li> <li class="earth"><span><span class="moon"></span></li> </ul> </div> <div class="right"> </div> </div> </body> </html>帮我完善我现在写的代码完成实验指导书内容
11-15
内容概要:本文介绍了ENVI Deep Learning V1.0的操作教程,重点讲解了如何利用ENVI软件进行深度学习模型的训练与应用,以实现遥感图像中特定目标(如集装箱)的自动提取。教程涵盖了从数据准备、标签图像创建、模型初始化与训练,到执行分类及结果优化的完整流程,并介绍了精度评价与通过ENVI Modeler实现一键化建模的方法。系统基于TensorFlow框架,采用ENVINet5(U-Net变体)架构,支持通过点、线、面ROI或分类图生成标签数据,适用于多/高光谱影像的单一类别特征提取。; 适合人群:具备遥感图像处理基础,熟悉ENVI软件操作,从事地理信息、测绘、环境监测等相关领域的技术人员或研究人员,尤其是希望将深度学习技术应用于遥感目标识别的初学者与实践者。; 使用场景及目标:①在遥感影像中自动识别和提取特定地物目标(如车辆、建筑、道路、集装箱等);②掌握ENVI环境下深度学习模型的训练流程与关键参数设置(如Patch Size、Epochs、Class Weight等);③通过模型调优与结果反馈提升分类精度,实现高效自动化信息提取。; 阅读建议:建议结合实际遥感项目边学边练,重点关注标签数据制作、模型参数配置与结果后处理环节,充分利用ENVI Modeler进行自动化建模与参数优化,同时注意软硬件环境(特别是NVIDIA GPU)的配置要求以保障训练效率。
内容概要:本文系统阐述了企业新闻发稿在生成式引擎优化(GEO)时代下的全渠道策略与效果评估体系,涵盖当前企业传播面临的预算、资源、内容与效果评估四大挑战,并深入分析2025年新闻发稿行业五大趋势,包括AI驱动的智能化转型、精准化传播、首发内容价值提升、内容资产化及数据可视化。文章重点解析央媒、地方官媒、综合门户和自媒体四类媒体资源的特性、传播优势与发稿策略,提出基于内容适配性、时间节奏、话题设计的策略制定方法,并构建涵盖品牌价值、销售转化与GEO优化的多维评估框架。此外,结合“传声港”工具实操指南,提供AI智能投放、效果监测、自媒体管理与舆情应对的全流程解决方案,并针对科技、消费、B2B、区域品牌四大行业推出定制化发稿方案。; 适合人群:企业市场/公关负责人、品牌传播管理者、数字营销从业者及中小企业决策者,具备一定媒体传播经验并希望提升发稿效率与ROI的专业人士。; 使用场景及目标:①制定科学的新闻发稿策略,实现从“流量思维”向“价值思维”转型;②构建央媒定调、门户扩散、自媒体互动的立体化传播矩阵;③利用AI工具实现精准投放与GEO优化,提升品牌在AI搜索中的权威性与可见性;④通过数据驱动评估体系量化品牌影响力与销售转化效果。; 阅读建议:建议结合文中提供的实操清单、案例分析与工具指南进行系统学习,重点关注媒体适配性策略与GEO评估指标,在实际发稿中分阶段试点“AI+全渠道”组合策略,并定期复盘优化,以实现品牌传播的长期复利效应。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值