diff --git a/solutions/1072. Flip Columns For Maximum Number of Equal Rows/1072.cs b/solutions/1072. Flip Columns For Maximum Number of Equal Rows/1072.cs new file mode 100644 index 0000000..e4b43b2 --- /dev/null +++ b/solutions/1072. Flip Columns For Maximum Number of Equal Rows/1072.cs @@ -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 seen = new HashSet(); + + 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; + } +} \ No newline at end of file diff --git a/solutions/400. Nth Digit/400.cs b/solutions/400. Nth Digit/400.cs new file mode 100644 index 0000000..4418f75 --- /dev/null +++ b/solutions/400. Nth Digit/400.cs @@ -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'; + } +} \ No newline at end of file