コード例 #1
0
ファイル: Program.cs プロジェクト: Woodoocubic/LeetCode
        public int LeftfMostColumnWithOne2(BinaryMatrix binaryMatrix)
        {
            var row = binaryMatrix.Dimensions()[0];
            var col = binaryMatrix.Dimensions()[1];
            int c = col - 1;
            int r = 0;
            int mostLeft = col;

            while (c >= 0 && r<row)
            {
                if (binaryMatrix.Get(r, c) == 1)
                {
                    c--;
                }
                else
                {
                    r++;
                }

                mostLeft = Math.Min(c + 1, mostLeft);
            }

            return mostLeft == col ? -1 : mostLeft;
        }