IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

跳水板

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

跳水板

你正在使用一堆木板建造跳水板。有两种类型的木板,其中长度较短的木板长度为shorter,长度较长的木板长度为longer。你必须正好使用k块木板。编写一个方法,生成跳水板所有可能的长度。

返回的长度需要从小到大排列。

示例

输入:
shorter = 1
longer = 2
k = 3
输出: {3,4,5,6}

题解

/**
 * @param {number} shorter
 * @param {number} longer
 * @param {number} k
 * @return {number[]}
 */
var divingBoard = function(shorter, longer, k) {
    if(k === 0) return [];
    if(shorter === longer) return [ longer * k ];
    var target = [];
    for(let i=0; i<=k; ++i) target.push( shorter*(k-i) + longer*i);
    return target;
};

思路

按照本题要求,必须使用k块木板,那么只需要维护一个长度为k的定长滑动窗口即可,首先滑动窗口中全部放置短的木板,之后将窗口滑动,也就是依次将短的木板移出然后将长的木板亦如,考虑到两个边界情况,当k的长度为0时只需要返回空数组即可,当长木板长度等于端木板长度时,只有一种情况即木板长度乘模板数量。首先处理边界情况,k === 0时直接返回空数组,在shorter === longer情况下返回只有longer * k一个值的数组,在处理滑动窗口的过程中,当需要的木板数量为k时会生成k+1中情况,也就是需要k+1次循环,然后以i为分割点,因为其是从小到大排列,所以首先将窗口中装满shorter长度的木板,再依次滑动计算即可。

每日一题

https://github.com/WindrunnerMax/EveryDay

题源

https://leetcode-cn.com/problems/diving-board-lcci/

文章永久链接:https://tech.souyunku.com/?p=39643


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(81) 打赏



未经允许不得转载:搜云库技术团队 » 跳水板

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367