16.16. 部分排序

class Solution {
    public int[] subSort(int[] nums) {
    	if (nums.length == 0) return new int[] { -1, -1 };
    	
    	// 从左扫描到右寻找逆序对(正序:逐渐变大)
    	int max = nums[0];
    	// 用来记录最右的那个逆序对位置
    	int r = -1;
    	for (int i = 1; i < nums.length; i++) {
			if (nums[i] >= max) {
				max = nums[i];
			} else {
				r = i;
			}
		}
    	
    	// 提前结束
    	if (r == -1) return new int[] { -1, -1 };
    	
    	// 从右扫描到左寻找逆序对(正序:逐渐变小)
    	int min = nums[nums.length - 1];
    	// 用来记录最左的那个逆序对位置
    	int l = -1;
    	for (int i = nums.length - 2; i >= 0; i--) {
			if (nums[i] <= min) {
				min = nums[i];
			} else {
				l = i;
			}
		}
    	
        return new int[] { l, r };
    }
}

 

 

/* Navicat Premium Data Transfer Source Server : 16.16.0.2 Source Server Type : SQL Server Source Server Version : 11002100 Source Host : 16.16.0.2:1433 Source Catalog : SummerFreshData_JX Source Schema : dbo Target Server Type : SQL Server Target Server Version : 11002100 File Encoding : 65001 Date: 16/09/2025 16:10:30 */ -- ---------------------------- -- Table structure for TownStationAccess -- ---------------------------- IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[TownStationAccess]') AND type IN ('U')) DROP TABLE [dbo].[TownStationAccess] GO CREATE TABLE [dbo].[TownStationAccess] ( [ID] int IDENTITY(1,1) NOT NULL, [CityName] varchar(100) COLLATE Chinese_PRC_CI_AS NOT NULL, [UniqueCode] varchar(100) COLLATE Chinese_PRC_CI_AS NOT NULL, [PositionName] varchar(100) COLLATE Chinese_PRC_CI_AS NOT NULL, [AccessTime] datetime NULL ) GO ALTER TABLE [dbo].[TownStationAccess] SET (LOCK_ESCALATION = TABLE) GO -- ---------------------------- -- Records of TownStationAccess -- ---------------------------- SET IDENTITY_INSERT [dbo].[TownStationAccess] ON GO SET IDENTITY_INSERT [dbo].[TownStationAccess] OFF GO -- ---------------------------- -- Auto increment value for TownStationAccess -- ---------------------------- DBCC CHECKIDENT ('[dbo].[TownStationAccess]', RESEED, 780) GO -- ---------------------------- -- Primary Key structure for table TownStationAccess -- ---------------------------- ALTER TABLE [dbo].[TownStationAccess] ADD CONSTRAINT [pk_TownStationAccess] PRIMARY KEY CLUSTERED ([ID]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO 将SQL 转换为金仓数据库可执行语句
最新发布
09-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值