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

建立企业网站的意义手机论坛网站

建立企业网站的意义,手机论坛网站,厦门网站建设平台,2023北京又开始核酸了吗今天初始化数据结构#xff1a; 使用一个布尔数组 arr 来表示每个位置是否被占用。初始时所有位置均为 false#xff08;未占用#xff09;。使用一个 LinkedHashMap#xff08;命名为 queue#xff09;来记录最近的 R 操作的位置。这个结构可以保持插入顺序#xff0c;方便后… 初始化数据结构 使用一个布尔数组 arr 来表示每个位置是否被占用。初始时所有位置均为 false未占用。使用一个 LinkedHashMap命名为 queue来记录最近的 R 操作的位置。这个结构可以保持插入顺序方便后续处理。 遍历输入字符串 遍历每个字符根据字符的类型.、L、R进行不同的处理 .表示空位跳过。L 如果 queue 为空没有 R将当前位置之前的所有位置标记为占用true。如果 queue 不为空处理最近的 R 从 queue 中获取并移除最近的 R 的位置。计算从这个 R 到当前 L 之间的影响区域并根据位置关系决定标记的方式。具体来说如果 L 和 R 之间的距离是偶数则需要跳过中间位置如果是奇数则可以直接标记所有位置为占用。R将当前索引加入 queue以备后续处理。 处理剩余的 R 遍历完字符串后如果 queue 中还有 R取出第一个 R 的位置将这个位置及其后所有位置标记为占用。 计算未占用的位置 遍历 arr 数组统计未被占用的位置并将它们的索引1-based加入结果队列。 构造结果字符串 如果没有未占用的位置返回 0。否则构造结果字符串格式为 count:pos1,pos2,...并返回。 import java.util.ArrayDeque; import java.util.LinkedHashMap; import java.util.Map; import java.util.Iterator;public class Main {public static String solution(int num, String data) {boolean[] arr new boolean[data.length()];LinkedHashMapCharacter, Integer queue new LinkedHashMap();for (int i 0; i data.length(); i) {switch (data.charAt(i)) {case .:break;case L:if (queue.isEmpty()) {for (int j 0; j i; j) {arr[j] true;}} else {IteratorMap.EntryCharacter, Integer iterator queue.entrySet().iterator();Map.EntryCharacter, Integer firstEntry iterator.next(); // 获取第一个条目iterator.remove();boolean skipTwo false;int top firstEntry.getValue();int extra (i top) / 2;if ((i - top) % 2 ! 0) {skipTwo true;}for (int j top; j i; j) {if (skipTwo) {arr[j] true;} else {if (j ! extra) {arr[j] true;}}}}break;case R:queue.put(R, i);break;}}// Check if the queue is not emptyif (!queue.isEmpty()) {// Retrieve and remove the first entryIteratorMap.EntryCharacter, Integer iterator queue.entrySet().iterator();Map.EntryCharacter, Integer firstEntry iterator.next();iterator.remove(); // Pop the first entryif (firstEntry.getKey() R) {int topValue firstEntry.getValue();for (int j topValue; j arr.length; j) {arr[j] true; // Set all subsequent elements to true}}}int count 0;ArrayDequeInteger result new ArrayDeque();for (int i 0; i data.length(); i) {if (!arr[i]) {count;result.add(i 1); // 1-based index}}if (count 0) {return 0; // All positions are filled}StringBuilder resultString new StringBuilder(count :);for (int pos : result) {resultString.append(pos).append(,);}resultString.setLength(resultString.length() - 1); // Remove the last commareturn resultString.toString();}public static void main(String[] args) {// // You can add more test cases hereSystem.out.println(solution(14, .L.R...LR..L..).equals(4:3,6,13,14));System.out.println(solution(5, R....).equals(0));System.out.println(solution(1, .).equals(1:1));} }
http://www.hkea.cn/news/14447476/

相关文章:

  • 机械网站建设免费设计logo效果图
  • 壹网优化站诊断
  • 当富广州网站建设网站导航栏设计要求
  • 全州建设完小网站网站建设的资源整合与系统设计
  • 毕业设计代做网站都有哪些软件开发模型案例
  • 做影视网站风险大开一个网店需要多少钱
  • 财务管理做的好的门户网站果麦传媒的网站怎么做的
  • 制作网站要花多少钱长春网络建设公司
  • 网站建设知识平台事业单位网站建设的作用
  • html5网站建设破解asp网站后台地址
  • 设置网站解析湖南做网站 都来磐石网络
  • 公司改名网站备案深圳网站建设服务有限公司
  • 网站建设基础入门铁岭 建筑公司网站 中企动力建设
  • 南京网站优化哪家好外贸服装商城网站建设
  • 网站建设公司ttmwl临沂建设大型网站建设
  • 联想公司网站建设现状无限成都成都市广播电视台官方网站
  • 网站建设销售工作怎么样瑞诺国际的数字营销模式
  • 五莲网站建设网络广告策划的内容
  • 做2手物品通过网站去卖掉好做吗木地板企业网站模版
  • 青岛网站建设seo优化凡科的网站怎么仿
  • 遵义市双控体系建设网站徐州焊接球网架公司
  • 机电建设工程施工网站百度关键词点击价格查询
  • 深圳本地做网站android开发基础教程
  • 建设人才证书查询网站孩子学编程的利弊
  • 人力招聘网站建设任务执行书上海外贸公司招聘职位
  • 金华金义东轨道建设网站织梦中二次开发新的网站
  • 河南省建设厅官方网站李学军网站建设与发布需要什么
  • 深圳做微信网站建设分发平台
  • 手机wap网站如何建设网站建设咨询云尚网络
  • 自己怎么建网站一般网站的后台