Skip to content

Commit

Permalink
feat: DCC 22-11-2024 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
cvalingam committed Nov 22, 2024
1 parent 12c18ea commit 6a5035e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
public class Solution
{
public int MaxEqualRowsAfterFlips(int[][] matrix)
{
int m = matrix.Length;
int n = matrix[0].Length;
int ans = 0;
int[] flip = new int[n];
HashSet<int> seen = new HashSet<int>();

for (int i = 0; i < m; ++i)
{
if (seen.Contains(i))
continue;

int count = 0;

for (int j = 0; j < n; ++j)
flip[j] = 1 ^ matrix[i][j];

for (int k = 0; k < m; ++k)
{
if (AreArraysEqual(matrix[k], matrix[i]) || AreArraysEqual(matrix[k], flip))
{
seen.Add(k);
++count;
}
}

ans = Math.Max(ans, count);
}

return ans;
}

private bool AreArraysEqual(int[] a, int[] b)
{
if (a.Length != b.Length)
return false;

for (int i = 0; i < a.Length; i++)
{
if (a[i] != b[i])
return false;
}

return true;
}
}
21 changes: 21 additions & 0 deletions solutions/400. Nth Digit/400.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Solution
{
public int FindNthDigit(int n)
{
int digitSize = 1;
int startNum = 1;
long count = 9;

while (digitSize * count < n)
{
n -= digitSize * (int)count;
++digitSize;
startNum *= 10;
count *= 10;
}

int targetNum = startNum + (n - 1) / digitSize;
int index = (n - 1) % digitSize;
return (int)(targetNum.ToString()[index]) - '0';
}
}

0 comments on commit 6a5035e

Please sign in to comment.