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

dlink nas做网站网站建设开发企业

dlink nas做网站,网站建设开发企业,路由器设置网站,天津房屋装修设计公司问题背景 在一排多米诺骨牌中, t o p s [ i ] tops[i] tops[i] 和 b o t t o m s [ i ] bottoms[i] bottoms[i] 分别代表第 i i i 个多米诺骨牌的上半部分和下半部分。(一个多米诺是两个从 1 1 1 到 6 6 6 的数字同列平铺形成的 —— 该平铺的每一半…

问题背景

在一排多米诺骨牌中, t o p s [ i ] tops[i] tops[i] b o t t o m s [ i ] bottoms[i] bottoms[i] 分别代表第 i i i 个多米诺骨牌的上半部分和下半部分。(一个多米诺是两个从 1 1 1 6 6 6 的数字同列平铺形成的 —— 该平铺的每一半上都有一个数字。)
我们可以旋转第 i i i 张多米诺,使得 t o p s [ i ] tops[i] tops[i] b o t t o m s [ i ] bottoms[i] bottoms[i] 的值交换。
返回能使 t o p s tops tops 中所有值或者 b o t t o m s bottoms bottoms 中所有值都相同的最小旋转次数。
如果无法做到,返回 − 1 -1 1

数据约束

  • 2 ≤ t o p s . l e n g t h ≤ 2 × 1 0 4 2 \le tops.length \le 2 \times 10 ^ 4 2tops.length2×104
  • b o t t o m s . l e n g t h = t o p s . l e n g t h bottoms.length = tops.length bottoms.length=tops.length
  • 1 ≤ t o p s [ i ] , b o t t o m s [ i ] ≤ 6 1 \le tops[i], bottoms[i] \le 6 1tops[i],bottoms[i]6

解题过程

结果要求所有元素都相同,那这意味着如果最后能实现,那么取初始状态的任意一个元素,它或它的翻转状态一定被包含在结果中。
为了方便起见,分别取 t o p [ 0 ] top[0] top[0] b o t t o m [ 0 ] bottom[0] bottom[0] 作为目标,分别计算最小次数,再取其中较小的那个就可以了。

具体实现

class Solution {public int minDominoRotations(int[] tops, int[] bottoms) {int res = Math.min(minRot(tops, bottoms, tops[0]), minRot(tops, bottoms, bottoms[0]));return res == Integer.MAX_VALUE ? -1 : res;}private int minRot(int[] tops, int[] bottoms, int target) {int toTop = 0;int toBottom = 0;for (int i = 0; i < tops.length; i++) {int x = tops[i];int y = bottoms[i];if (x != target && y != target) {return Integer.MAX_VALUE;}if (x != target) {toTop++; } else if (y != target) {toBottom++;}}return Math.min(toTop, toBottom);}
}

文章转载自:

http://jy4q2pWl.pgcmz.cn
http://sxmBoW4N.pgcmz.cn
http://1M2iYFc3.pgcmz.cn
http://72m4n5pN.pgcmz.cn
http://xG3JC4Tn.pgcmz.cn
http://uHnh3hn5.pgcmz.cn
http://Mjw3dZnD.pgcmz.cn
http://b8ytHnuQ.pgcmz.cn
http://ppEiiVrV.pgcmz.cn
http://jHQ8ETqi.pgcmz.cn
http://SHPxVg9G.pgcmz.cn
http://egyHUsXW.pgcmz.cn
http://w9mzcpvD.pgcmz.cn
http://NoAPbqoj.pgcmz.cn
http://4BupOcSz.pgcmz.cn
http://lwyQLTwF.pgcmz.cn
http://8oqDZOuu.pgcmz.cn
http://m9O9H42l.pgcmz.cn
http://dxLWGOZX.pgcmz.cn
http://dI60rRDE.pgcmz.cn
http://MpO4SM0X.pgcmz.cn
http://PbsNyIIL.pgcmz.cn
http://pUwJ0djQ.pgcmz.cn
http://Snfc0KwE.pgcmz.cn
http://XdYpFmTv.pgcmz.cn
http://CrsxHAnf.pgcmz.cn
http://mSd1lZxq.pgcmz.cn
http://McH5GJzX.pgcmz.cn
http://wbnkx9Hn.pgcmz.cn
http://gXk0RtXd.pgcmz.cn
http://www.dtcms.com/wzjs/725096.html

相关文章:

  • 网站开发建设交印花税吗微信官方网站下载
  • 湖南3合1网站建设价格广州建设银行招聘网站
  • 营销型网站整体优化国展做网站的公司
  • 陕西省交通建设集团公司网站商贸公司起名字大全免费
  • 做商城网站要哪些流程图整合营销英文
  • 中国石油天然气第七建设公司网站给你一个网站怎么优化
  • 山西运城给网站做系统的公司建网站的成本计算
  • 桂林北站地址泉州网站建设-泉州网站建设
  • 做机械的网站有哪些网页建站
  • 每个城市建设规划在哪个网站网站备案最快几天
  • 找人做网站去哪里wordpress 主题制作 视频
  • 服务器网站管理助手wordpress付费可见
  • 怎么免费搭建网站怎么用微信做网站
  • 网站主题咋做本科专业建设规划
  • 重庆网站推广运营公司会网站开发想找兼职
  • 怎样注册网站免费注册微信app定制开发
  • 网络营销推广公司策划方案有实力的网站排名优化软件
  • 中小企业建站服务制作企业网站用什么软件
  • 丹东谁做微网站wordpress版本信息在哪里查看
  • 网站被k 申诉私密浏览器如何下载视频
  • 贵州建设项目门户网站wordpress缩略图排列
  • 辽宁网站制作公司网页设计网上培训班
  • 购物网站答辩ppt怎么做网站关键词选择
  • 做公司展示网站建设网站的编程过程
  • 网站源码下载视频网站开发后端 书
  • 服务器网站绑定域名网站建设网站策划与建设实训心得
  • 制作网站哪家便宜慈溪seo排名
  • 遂宁网站建设手机端网站建设郑州
  • dw怎么制作网页教程绍兴seo
  • 中国建设网站官网新浪虚拟主机做网站