
1 gasonzhong1 2023-02-24 10:04:32 +08:00 改成这样就好了 contract FunctionTypes { function insertSort(uint256[] memory arr) external returns (uint256[] memory) { for (uint256 i = 1; i < uint256(arr.length); i++) { uint256 temp = arr[i]; for (uint256 j = i - 1; j >= 0; j--) { if (arr[j] >= temp) arr[j + 1] = arr[j]; else { arr[j + 1] = temp; } } } return arr; } } |
2 helloworld2048 OP @gasonzhong1 感谢 int 为什么不行呢?因为 j 为负数跳出循环时用 uint 会报错,需要再单独处理一下,所以我想用 int 会更方便一些 |
3 pengjay 2023-02-24 11:24:58 +08:00 arr[i]里的 i 只能是 uint 吧 |
4 helloworld2048 OP @pengjay 这样的 感谢~ |