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. Linux下weblogic启动报错unable to get file lock的问题

    非正常结束weblogic进程导致weblogic无法启动 由于先前服务器直接down掉了,所有进程都非正常的进行关闭了,也就导致了下次启动weblogic的时候报了以下错误:<2012-3-2 ...

  2. ActiveX开发

    转自(http://blog.csdn.net/mingojiang/article/details/8159263) 一.ActiveX基础 1.1什么是ActiveX ActiveX是COM规范的 ...

  3. windows下使用python的scrapy爬虫框架,爬取个人博客文章内容信息

    scrapy作为流行的python爬虫框架,简单易用,这里简单介绍如何使用该爬虫框架爬取个人博客信息.关于python的安装和scrapy的安装配置请读者自行查阅相关资料,或者也可以关注我后续的内容. ...

  4. jsp登录页面,展示错误信息,刷新页面后错误依然存在解决方案

    在做登录页面的时候,通常使用form表单同步提交的方法进行提交的,也就是在form表单里去写action,如果登录失败,jsp通过jstl表达式获取错误信息展示在页面上,但是有一个问题就是,即使你刷新 ...

  5. Centos7 防火墙常用命令 开启 关闭防火墙

    如果你的系统上没有安装使用命令安装 #yum install firewalld  //安装firewalld 防火墙 开启服务 # systemctl start firewalld.service ...

  6. Pale Moon 苍月浏览器 24.0.1 发布

    火狐浏览器知名修改版—苍月浏览器Pale Moon今天发布24.0.1版本,该版本基于Firefox 最近更新的24.0.1正式版. 下载地址: 32位下载:http://relmirror.pale ...

  7. L194

    For many of us, asking for help is it difficult concept. We may feel as if we are admitting a weakne ...

  8. PostgreSQL设置事务隔离级别实验

    apple=# begin; BEGIN apple=# set transaction ISOLATION LEVEL read committed ; SET apple=# select * f ...

  9. python安装openSSL

    首先确定您是否下载python (3).pip (3).python-wheel 官网下载源码包openSSL 参考:用pip安装python 模块OpenSSL

  10. IE8 focus 失效解决方案

    这几天遇到两个在IE8下focus失效的非常奇怪的问题,当然这个是指JS函数: document.getElementById("id").focus(); 或者 $(" ...