Skip to content

Commit 6273e1d

Browse files
committed
2 parents de2ed86 + 0bf3e60 commit 6273e1d

8 files changed

+158
-3
lines changed

1572/my_solution.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @param {number[][]} mat
3+
* @return {number}
4+
*/
5+
var diagonalSum = function (mat) {
6+
let sum = 0, l = 0, r = mat[0].length - 1;
7+
8+
for (let row = 0; row < mat.length; row++) {
9+
// for (let c = 0; c < mat[r].length; c++) {
10+
console.log(`mat[row][l]:${mat[row][l]}, mat[row][r]:${mat[row][r]}`)
11+
if (l === r) { // intersect
12+
sum += mat[row][l];
13+
} else {
14+
sum += mat[row][l] + mat[row][r];
15+
}
16+
17+
l++;
18+
r--;
19+
// }
20+
}
21+
22+
return sum;
23+
};
24+
25+
let x = null;
26+
x = diagonalSum([
27+
[1, 2, 3],
28+
[4, 5, 6],
29+
[7, 8, 9]
30+
])
31+
32+
33+
console.log("Result");
34+
console.log(x);

1572/solution.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number[][]} mat
3+
* @return {number}
4+
*/
5+
var diagonalSum = function (mat) {
6+
let sum = 0, l = 0, r = mat[0].length - 1;
7+
8+
for (let row = 0; row < mat.length; row++) {
9+
if (l === r) {
10+
sum += mat[row][l];
11+
} else {
12+
sum += mat[row][l] + mat[row][r];
13+
}
14+
15+
l++;
16+
r--;
17+
}
18+
19+
return sum;
20+
};
21+

2448/my_solution.js

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2448/solution.js

Whitespace-only changes.

832/my_solution.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @param {number[][]} image
3+
* @return {number[][]}
4+
*/
5+
const flipAndInvertImage = (image) => {
6+
// let result = Array.from({ length: image.length }, () => Array.from({ length: image[0].length }, () => []));
7+
// console.log(result)
8+
for (let row = 0; row < image.length; row++) {
9+
let tmpArray = Array.from({ length: image[row].length }, () => []);
10+
console.log(tmpArray)
11+
for (let col = 0; col < image[row].length; col++) {
12+
// result[row][image[row].length - 1 - col] = image[row][col] ^ 1;
13+
tmpArray[image[row].length - 1 - col] = image[row][col] ^ 1;
14+
}
15+
console.log(tmpArray)
16+
console.log(image)
17+
image[row] = tmpArray
18+
console.log(image)
19+
}
20+
return image;
21+
};
22+
23+
let x = null;
24+
x = flipAndInvertImage([[1, 1, 0], [1, 0, 1], [0, 0, 0]])
25+
console.log("Result")
26+
console.log(x)

832/solution.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @param {number[][]} image
3+
* @return {number[][]}
4+
*/
5+
const flipAndInvertImage = (image) => { // inplace
6+
for (let row = 0; row < image.length; row++) {
7+
let tmpArray = Array.from({ length: image[row].length }, () => []);
8+
for (let col = 0; col < image[row].length; col++) {
9+
tmpArray[image[row].length - 1 - col] = image[row][col] ^ 1;
10+
}
11+
image[row] = tmpArray
12+
}
13+
return image;
14+
};
15+
16+
let x = null;
17+
x = flipAndInvertImage([[1, 1, 0], [1, 0, 1], [0, 0, 0]])
18+
console.log("Result")
19+
console.log(x)
20+
21+
22+
// const flipAndInvertImage = (image) => {
23+
// let result = Array.from({ length: image.length }, () => Array.from({ length: image[0].length }, () => []));
24+
// for (let row = 0; row < image.length; row++) {
25+
// for (let col = 0; col < image[row].length; col++) {
26+
// result[row][image[row].length - 1 - col] = image[row][col] ^ 1;
27+
// }
28+
// }
29+
// return result;
30+
// };

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,22 @@
6868
- [530. Minimum Absolute Difference in BST](./530/)
6969
- [647. Palindromic Substrings](./647/)
7070
- [771. Jewels and Stones](./771/)
71+
- [832. Flipping an Image](./832/)
7172
- [997. Find the Town Judge](./997/)
7273
- [1161. Maximum Level Sum of a Binary Tree](./1161/)
7374
- [1187. Make Array Strictly Increasing](./1187/)
7475
- [1365. How Many Numbers Are Smaller Than the Current Number](./1365/)
7576
- [1480. Running Sum of 1d Array](./1480/)
7677
- [1512. Number of Good Pairs](./1512/)
7778
- [1569. Number of Ways to Reorder Array to Get Same BST](./1569/)
79+
- [1572. Matrix Diagonal Sum](./1572/)
7880
- [1672. Richest Customer Wealth](./1672/)
7981
- [1791. Find Center of Star Graph](./1791/)
8082
- [1909. Remove One Element to Make the Array Strictly Increasing](./1909/)
8183
- [1971. Find if Path Exists in Graph](./1971/)
8284
- [2090. K Radius Subarray Averages](./2090/)
8385
- [2373. Largest Local Values in a Matrix](./2373/)
86+
- [2448. Minimum Cost to Make Array Equal](./2448/)
8487

8588
---
8689

@@ -106,7 +109,7 @@ iex ./.../solution.ex
106109

107110
Batch create:
108111
```ssh
109-
chapter=997 && mkdir ./$chapter && touch ./$chapter/my_solution.ex && touch ./$chapter/solution.ex && alias x="iex ./$chapter/my_solution.ex"
112+
chapter=1572 && mkdir ./$chapter && touch ./$chapter/my_solution.ex && touch ./$chapter/solution.ex && alias x="iex ./$chapter/my_solution.ex"
110113
```
111114
> then you can use `x` for quick debug.
112115
@@ -128,7 +131,7 @@ Batch create:
128131
NOTE: JS IS HERE
129132
-->
130133
```ssh
131-
chapter=1480 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
134+
chapter=832 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
132135
```
133136
> then you can use `x` for quick debug.
134137

test.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,15 @@
8888
// Decimal
8989
// console.log(Math.round(324631.99999999994));
9090

91-
console.log(0 > 0);
91+
// console.log(0 > 0);
92+
93+
console.log(0 ^ 0);
94+
console.log(1 ^ 0);
95+
// convert 0 -> 1; 1 -> 0
96+
console.log(0 ^ 1);
97+
console.log(1 ^ 1);
98+
console.log()
99+
console.log(0 & 0);
100+
console.log(1 & 0);
101+
console.log(0 & 1);
102+
console.log(1 & 1);

0 commit comments

Comments
 (0)