39. Minimum Time Difference

本文探讨了如何求解给定24小时制时间列表中任意两个时间点之间的最短分钟差,提供了两种方法实现:一种是直接转换为分钟并排序进行比较;另一种则是利用桶排序简化计算过程。

Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minutes difference between any two time points in the list.

Example 1:

Input: ["23:59","00:00"]
Output: 1

 

Note:

  1. The number of time points in the given list is at least 2 and won't exceed 20000.
  2. The input time is legal and ranges from 00:00 to 23:59.

求数组中,两点之间时钟间隔最小值。

方法一:先将时间表达式转化为分钟整数,排序,依次判断相邻两点的分钟间隔,注意跨零点的情况

方法二:因为时间表达式转化为分钟后,整数最大值为23*60+59,该数值不是很大,因此可以采用桶排序,程序如下所示:

class Solution {
    private final int MAX_LEN = 24*60;
    public int findMinDifference(List<String> timePoints) {
        int len = timePoints.size();
        boolean[] bucket = new boolean[MAX_LEN];
        int hour = 0, minute = 0, cur = 0;
        int left = MAX_LEN, right = 0;
        for (String val : timePoints){
            hour = Integer.parseInt(val.substring(0, 2));
            minute = Integer.parseInt(val.substring(val.length() - 2, val.length()));
            cur = hour * 60 + minute;
            if (bucket[cur]){
                return 0;
            }
            bucket[cur] = true;
            left = Math.min(left, cur);
            right = Math.max(right, cur);
        }
        int res = MAX_LEN;
        Integer pre = null;
        while (left <= right){
            while (!bucket[left]){
                left ++;
            }
            if (pre != null){
                res = Math.min(res, Math.min(left - pre, pre + MAX_LEN - right));
            }
            pre = left;
            left ++;
        }
        return res;
    }
}

 

pmsampsize(type = "s", csrsquared = 0.3, parameters = 10, shrinkage = 0.95, rate = 0.02, + timepoint = 10, meanfup = 5) NB: Assuming 0.05 acceptable difference in apparent & adjusted R-squared NB: Assuming 0.05 margin of error in estimation of overall risk at time point = 10 NB: Events per Predictor Parameter (EPP) assumes overall event rate = 0.02 Samp_size Shrinkage Parameter CS_Rsq Max_Rsq Nag_Rsq EPP Criteria 1 528 0.950 10 0.3 0.483 0.621 5.28 Criteria 2 343 0.925 10 0.3 0.483 0.621 3.43 Criteria 3 * 528 0.950 10 0.3 0.483 0.621 5.28 Final SS 528 0.950 10 0.3 0.483 0.621 5.28 Minimum sample size required for new model development based on user inputs = 528, corresponding to 2640 person-time** of follow-up, with 53 outcome events assuming an overall event rate = 0.02 and therefore an EPP = 5.28 * 95% CI for overall risk = (0.136, 0.224), for true value of 0.181 and sample size n = 528 **where time is in the units mean follow-up time was specified in > pmsampsize(type = "s", csrsquared = 0.15, parameters = 10, shrinkage = 0.95, rate = 0.02, + timepoint = 10, meanfup = 5) NB: Assuming 0.05 acceptable difference in apparent & adjusted R-squared NB: Assuming 0.05 margin of error in estimation of overall risk at time point = 10 NB: Events per Predictor Parameter (EPP) assumes overall event rate = 0.02 Samp_size Shrinkage Parameter CS_Rsq Max_Rsq Nag_Rsq EPP Criteria 1 1164 0.950 10 0.15 0.483 0.31 11.64 Criteria 2 377 0.861 10 0.15 0.483 0.31 3.77 Criteria 3 * 1164 0.950 10 0.15 0.483 0.31 11.64 Final SS 1164 0.950 10 0.15 0.483 0.31 11.64 Minimum sample size required for new model development based on user inputs = 1164, corresponding to 5820 person-time** of follow-up, with 117 outcome events assuming an overall event rate = 0.02 and therefore an EPP = 11.64 * 95% CI for overall risk = (0.151, 0.21), for true value of 0.181 and sample size n = 1164 **where time is in the units mean follow-up time was specified in(解读,为什么CS_R²从0.3设置为0.15时,样本量增加了????)
09-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值