Skip to content

Commit 5d476c7

Browse files
committed
maximumSwap优化
1 parent 5cd470d commit 5d476c7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

solutions/medium/maximumSwap.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ The given number is in the range [0, 10^8]
2525
### Solution
2626

2727
```javascript
28-
const maximumSwap = (num) => {
28+
const maximumSwap = function(num) {
2929
const arr = ''.split.call(num, '')
3030
const swapArr = (arr) => {
31-
const max = Math.max.apply(null, arr)
32-
const lastIndex = arr.lastIndexOf(max.toString())
31+
const max = Math.max.apply(null, arr).toString()
32+
const lastIndex = arr.lastIndexOf(max)
3333
if (lastIndex > 0 && arr[0] !== max) {
3434
arr[lastIndex] = arr[0]
3535
arr[0] = max

0 commit comments

Comments
 (0)