Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c3945a0

Browse files
Use isUpper function for uppercase character check
Refactor character case check to use isUpper function.
1 parent 0aa92f4 commit c3945a0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

‎3552-grid-teleportation-traversal.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var minMoves = function (matrix) {
3737
if (x === n - 1 && y === m - 1) return curDist
3838

3939
if (
40-
matrix[x][y].toUpperCase()===matrix[x][y] &&
40+
isUpper(matrix[x][y]) &&
4141
!used.has(matrix[x][y])
4242
) {
4343
used.add(matrix[x][y])
@@ -66,6 +66,13 @@ var minMoves = function (matrix) {
6666

6767
return -1
6868
}
69+
70+
function isUpper(ch) {
71+
const A = 'A'.charCodeAt(0)
72+
const Z = 'Z'.charCodeAt(0)
73+
const code = ch.charCodeAt(0)
74+
return code >= A && code <= Z
75+
}
6976
function isValid(i, j, n, m, matrix) {
7077
if (i < 0 || j < 0 || i >= n || j >= m) return false
7178
if (matrix[i][j] === '#') return false

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /