[LC] 1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
class Solution {
public int minDominoRotations(int[] A, int[] B) {
int[] countA = new int[7];
int[] countB = new int[7];
int[] same = new int[7];
int n = A.length;
for (int i = 0; i < n; i++) {
countA[A[i]] += 1;
countB[B[i]] += 1;
if (A[i] == B[i]) {
same[A[i]] += 1;
}
}
for (int i = 1; i <= 6; i++) {
if (countA[i] + countB[i] - same[i] == n) {
return n - Math.max(countA[i], countB[i]);
}
}
return -1;
}
}
[LC] 1007. Minimum Domino Rotations For Equal Row的更多相关文章
- 1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domi ...
- 【leetcode】1007. Minimum Domino Rotations For Equal Row
题目如下: In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. ( ...
- 【LeetCode】1007. Minimum Domino Rotations For Equal Row 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历一遍 日期 题目地址:https://leetc ...
- [Swift]LeetCode1007. 行相等的最少多米诺旋转 | Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domi ...
- Minimum Domino Rotations For Equal Row LT1007
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domi ...
- Leetcode: Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domin ...
- LC 712. Minimum ASCII Delete Sum for Two Strings
Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal. ...
- LC 983. Minimum Cost For Tickets
In a country popular for train travel, you have planned some train travelling one year in advance. ...
- LC 539. Minimum Time Difference
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...
随机推荐
- quartz详解3:quartz数据库集群-锁机制
http://blog.itpub.NET/11627468/viewspace-1764753/ 一.quartz数据库锁 其中,QRTZ_LOCKS就是Quartz集群实现同步机制的行锁表,其表结 ...
- Mybatis之配置文件
Mybatis_config.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE conf ...
- HTTP协议(四):首部
前言 作者说:上一节中介绍了HTTP报文中的状态码,这一节同样是对报文的补充,介绍的是HTTP首部字段.不过,你如果是第一次见到这个东西,肯定会特别疑惑,什么是HTTP首部? <图解HTTP&g ...
- CodeForces 1000B Light It Up(贪心、思维)
https://codeforces.com/problemset/problem/1000/B 题意: 一个模拟思维题.就是有一盏灯,0时刻开着.n次操作,你可以在其中加入一次操作(或者不加),操作 ...
- LeetCode——139. 单词拆分
给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词. 说明: 拆分时可以重复使用字典中的单词. 你可以假设字典中没有重复 ...
- 19.3.8 HTML+css 课程
form 归属于 form 通过id产生联系 <form id = "testform" method = "get" action = "s ...
- 【Python】关于import QtCore报错的处理方法
刚开始学习使用PyQT,但总碰到一些小挫折 比如 import Pyqt成功 而 from PyQt5 import QtCore, QtGui, QtWidgets却报错,找了半天终于找到资料,原因 ...
- 吴裕雄--天生自然MySQL学习笔记:MySQL 删除数据表
MySQL中删除数据表是非常容易操作的, 但是在进行删除表操作时要非常小心,因为执行删除命令后所有数据都会消失. 语法 以下为删除MySQL数据表的通用语法: DROP TABLE table_nam ...
- HTML 回到顶部 浮动
回到顶部 <div id="FloatDIV" style="position: absolute; top: 0px; z-index: 9999; backgr ...
- POJ 1258:Agri-Net Prim最小生成树模板题
Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 45050 Accepted: 18479 Descri ...