You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classLC_31 {
funnextPermutation(nums:IntArray): Unit {
val len = nums.size
var pivot =-1for (i in len -1 downTo 1) {
if (nums[i -1] < nums[i]) { // 증가하는 부분 찾기
pivot = i -1break
}
}
if (pivot ==-1) {
nums.reverse()
return
}
for (i in len -1 downTo 0) {
if (nums[pivot] < nums[i]) {
// Swap pivot과 해당 값
nums[pivot] = nums[i].also { nums[i] = nums[pivot] }
break
}
}
nums.reverse(pivot +1, len)
}
}
The text was updated successfully, but these errors were encountered:
Problem link
https://leetcode.com/problems/next-permutation/description/
Problem Summary
Solution
Source Code
The text was updated successfully, but these errors were encountered: