public class Solution
{
public int MatrixScore(int[][] A)
{
var row = A.GetLength();
var col = A[].GetLength();
//判断最高位是否为1
for (int i = ; i < row; i++)
{
if (!(A[i][] == ))//不是1,则移动此行
{
for (int j = ; j < col; j++)
{
if (A[i][j] == )
{
A[i][j] = ;
}
else
{
A[i][j] = ;
}
}
}
} //遍历每一列,计算0和1的数量,如果0多,则移动
for (int j = ; j < col; j++)
{
var sum0 = ;
var sum1 = ;
for (int i = ; i < row; i++)
{
if (A[i][j] == )
{
sum0++;
}
else
{
sum1++;
}
}
if (sum0 > sum1)
{
for (int i = ; i < row; i++)
{
if (A[i][j] == )
{
A[i][j] = ;
}
else
{
A[i][j] = ;
}
}
}
} //计算最后的二进制数
var sum = ;
for (int i = ; i < row; i++)
{
var rowsum = ;
for (int j = col - ; j >= ; j--)
{
var cur = A[i][j] * (int)Math.Pow(, col - - j);
rowsum += cur;
}
sum += rowsum;
} return sum;
}
}

leetcode861的更多相关文章

  1. [Swift]LeetCode861. 翻转矩阵后的得分 | Score After Flipping Matrix

    We have a two dimensional matrix A where each value is 0 or 1. A move consists of choosing any row o ...

随机推荐

  1. OATable中column栏位数据居中的实现方法及代码

    // Table column中显示居中的实现 // QpriceResultTable1 为table的名称 // noPrice 为table中的列 OATableBean table = (OA ...

  2. Constructor vs Object

    1. Constructor:是用于创建和初始化类中创建的一个对象的一种特殊方法. constructor([arguments]) { ... } 在一个类中只能有一个名为 “constructor ...

  3. ASPX 后台调用前台Js

    1.UpdatePanel 使用中 protected void Button1_Click(object sender, EventArgs e) { this.Label1.Text = &quo ...

  4. Eclipse中使用Maven,报错“$MAVEN_HOME”

    1.今天在用eclipse时,执行maven命令,报错,如图"$MAVEN_HOME" 解决方案: 1.点击 windows---preferences,打开preferences ...

  5. MySQL 存储过程理解

    /********************************************************************************* * MySQL 存储过程理解 * ...

  6. cratedb 集群 docker-compose 安装试用

    关于集群的配置说明可以参考官方文档,或者es 文档 详细代码参考 https://github.com/rongfengliang/cratedb-cluster-docker 参考配置 docker ...

  7. hasura graphql schema 导出

    使用的是apollo 的插件 安装apollo npm install -g apollo 基本使用 因为我使用了模式拼接,所以地址有变动,一般是 http://host:port/v1alpha1/ ...

  8. 公共的Json操作类

    using System; using System.Data; using System.Text; using System.Collections.Generic; using System.R ...

  9. 采用轻量ServiceMesh实现灰度发布的实践

    软件总会有缺陷的,解决问题的同时往往会引入新的问题,关键是看这些问题是否在我们的控制范围内,“灰度发布”就是让问题受控的方法之一. 前言 我们的 CTO 经常说:“研发团队最首要的任务是提供稳定的服务 ...

  10. 【linux】查看linux版本和内核版本

    查看linux版本:uname -r 查看linux版本内核:lsb_release -a