[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 ...
随机推荐
- DES与MD5加密
using System; using System.Data; using System.Configuration; using System.Web; using System.Security ...
- 2019.1的IDEA的Pulgins无法使用解决
第一步 第二步
- Spring AOP复习
最近在翻<Spring In Action>Spring 实战这本书,重新了解了一下AOP的概念和思想并写了一个小Demo示例,记录在这里: 环境:intelliJ IDEA 2018.M ...
- Java底层魔术类Unsafe用法简述
1 引子 Java中没有指针,不能直接对内存地址的变量进行控制,但Java提供了一个特殊的类Unsafe工具类来间接实现.Unsafe主要提供一些用于执行低级别.不安全操作的方法,如直接访问系统内存资 ...
- CTF -攻防世界-web高手区-mfw
---恢复内容开始--- 昂,我很菜这是网上大神的教程. https://blog.csdn.net/silence1_/article/details/89741733 ---恢复内容结束---
- ArrayList集合的增、删、改、获取和长度
API : code: package student; import java.util.ArrayList; public class ArrayListDemo { public static ...
- Servlet过滤器基础及使用场景
Servlet过滤器详解 一.过滤器基础 1.Servlet过滤器是Servlet的一种特殊用法,主要用来完成一些通用的操作.比如编码的过滤,判断用户的登陆状态等等.Servlet过滤器的适用场合: ...
- Spring中的控制反转和依赖注入
Spring中的控制反转和依赖注入 原文链接:https://www.cnblogs.com/xxzhuang/p/5948902.html 我们回顾一下计算机的发展史,从最初第一台计算机的占地面积达 ...
- UVA 11922 伸展树Splay 第一题
上次ZOJ月赛碰到一个题目要求对序列中的某个区间求gcd,并且还要随时对某位数字进行修改 插入 删除,当时马上联想到线段树,但是线段树不支持增删,明显还是不可以的,然后就敲了个链表想暴力一下,结果TL ...
- Android前后台切换的监听
本文参考这位哥们:https://juejin.im/post/5b87f409e51d4538b0640f58 首先写两个类文件ActivityLifecycleCallbacksAdapter.L ...