File tree Expand file tree Collapse file tree 4 files changed +182
-0
lines changed
solution/2600-2699/2614.Prime In Diagonal Expand file tree Collapse file tree 4 files changed +182
-0
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,36 @@ func isPrime(x int) bool {
194194}
195195```
196196
197+ #### TypeScript
198+
199+ ``` ts
200+ function diagonalPrime(nums : number [][]): number {
201+ const n = nums .length ;
202+ let ans = 0 ;
203+ for (let i = 0 ; i < n ; ++ i ) {
204+ if (isPrime (nums [i ][i ])) {
205+ ans = Math .max (ans , nums [i ][i ]);
206+ }
207+ if (isPrime (nums [i ][n - i - 1 ])) {
208+ ans = Math .max (ans , nums [i ][n - i - 1 ]);
209+ }
210+ }
211+ return ans ;
212+ }
213+
214+ function isPrime(x : number ): boolean {
215+ if (x < 2 ) {
216+ return false ;
217+ }
218+ for (let i = 2 ; i <= Math .floor (x / i ); ++ i ) {
219+ if (x % i === 0 ) {
220+ return false ;
221+ }
222+ }
223+ return true ;
224+ }
225+ ```
226+
197227#### Rust
198228
199229``` rust
@@ -231,6 +261,40 @@ impl Solution {
231261}
232262```
233263
264+ #### JavaScript
265+
266+ ``` js
267+ /**
268+ * @param {number[][]} nums
269+ * @return {number}
270+ */
271+ var diagonalPrime = function (nums ) {
272+ let ans = 0 ;
273+ const n = nums .length ;
274+ for (let i = 0 ; i < n; i++ ) {
275+ if (isPrime (nums[i][i])) {
276+ ans = Math .max (ans, nums[i][i]);
277+ }
278+ if (isPrime (nums[i][n - i - 1 ])) {
279+ ans = Math .max (ans, nums[i][n - i - 1 ]);
280+ }
281+ }
282+ return ans;
283+ };
284+
285+ function isPrime (x ) {
286+ if (x < 2 ) {
287+ return false ;
288+ }
289+ for (let i = 2 ; i * i <= x; i++ ) {
290+ if (x % i === 0 ) {
291+ return false ;
292+ }
293+ }
294+ return true ;
295+ }
296+ ```
297+
234298<!-- tabs:end -->
235299
236300<!-- solution:end -->
Original file line number Diff line number Diff line change @@ -192,6 +192,36 @@ func isPrime(x int) bool {
192192}
193193```
194194
195+ #### TypeScript
196+
197+ ``` ts
198+ function diagonalPrime(nums : number [][]): number {
199+ const n = nums .length ;
200+ let ans = 0 ;
201+ for (let i = 0 ; i < n ; ++ i ) {
202+ if (isPrime (nums [i ][i ])) {
203+ ans = Math .max (ans , nums [i ][i ]);
204+ }
205+ if (isPrime (nums [i ][n - i - 1 ])) {
206+ ans = Math .max (ans , nums [i ][n - i - 1 ]);
207+ }
208+ }
209+ return ans ;
210+ }
211+
212+ function isPrime(x : number ): boolean {
213+ if (x < 2 ) {
214+ return false ;
215+ }
216+ for (let i = 2 ; i <= Math .floor (x / i ); ++ i ) {
217+ if (x % i === 0 ) {
218+ return false ;
219+ }
220+ }
221+ return true ;
222+ }
223+ ```
224+
195225#### Rust
196226
197227``` rust
@@ -229,6 +259,40 @@ impl Solution {
229259}
230260```
231261
262+ #### JavaScript
263+
264+ ``` js
265+ /**
266+ * @param {number[][]} nums
267+ * @return {number}
268+ */
269+ var diagonalPrime = function (nums ) {
270+ let ans = 0 ;
271+ const n = nums .length ;
272+ for (let i = 0 ; i < n; i++ ) {
273+ if (isPrime (nums[i][i])) {
274+ ans = Math .max (ans, nums[i][i]);
275+ }
276+ if (isPrime (nums[i][n - i - 1 ])) {
277+ ans = Math .max (ans, nums[i][n - i - 1 ]);
278+ }
279+ }
280+ return ans;
281+ };
282+
283+ function isPrime (x ) {
284+ if (x < 2 ) {
285+ return false ;
286+ }
287+ for (let i = 2 ; i * i <= x; i++ ) {
288+ if (x % i === 0 ) {
289+ return false ;
290+ }
291+ }
292+ return true ;
293+ }
294+ ```
295+
232296<!-- tabs:end -->
233297
234298<!-- solution:end -->
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[][] } nums
3+ * @return {number }
4+ */
5+ var diagonalPrime = function ( nums ) {
6+ let ans = 0 ;
7+ const n = nums . length ;
8+ for ( let i = 0 ; i < n ; i ++ ) {
9+ if ( isPrime ( nums [ i ] [ i ] ) ) {
10+ ans = Math . max ( ans , nums [ i ] [ i ] ) ;
11+ }
12+ if ( isPrime ( nums [ i ] [ n - i - 1 ] ) ) {
13+ ans = Math . max ( ans , nums [ i ] [ n - i - 1 ] ) ;
14+ }
15+ }
16+ return ans ;
17+ } ;
18+
19+ function isPrime ( x ) {
20+ if ( x < 2 ) {
21+ return false ;
22+ }
23+ for ( let i = 2 ; i * i <= x ; i ++ ) {
24+ if ( x % i === 0 ) {
25+ return false ;
26+ }
27+ }
28+ return true ;
29+ }
Original file line number Diff line number Diff line change 1+ function diagonalPrime ( nums : number [ ] [ ] ) : number {
2+ const n = nums . length ;
3+ let ans = 0 ;
4+ for ( let i = 0 ; i < n ; ++ i ) {
5+ if ( isPrime ( nums [ i ] [ i ] ) ) {
6+ ans = Math . max ( ans , nums [ i ] [ i ] ) ;
7+ }
8+ if ( isPrime ( nums [ i ] [ n - i - 1 ] ) ) {
9+ ans = Math . max ( ans , nums [ i ] [ n - i - 1 ] ) ;
10+ }
11+ }
12+ return ans ;
13+ }
14+
15+ function isPrime ( x : number ) : boolean {
16+ if ( x < 2 ) {
17+ return false ;
18+ }
19+ for ( let i = 2 ; i <= Math . floor ( x / i ) ; ++ i ) {
20+ if ( x % i === 0 ) {
21+ return false ;
22+ }
23+ }
24+ return true ;
25+ }
You can’t perform that action at this time.
0 commit comments