五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

LeetCode 2731. Movement of Robots

2023-06-14 09:10 作者:您是打尖兒還是住店呢  | 我要投稿

Some robots are standing on an infinite number line with their initial coordinates given by a?0-indexed?integer array?nums?and will start moving once given the command to move. The robots will move a unit distance each second.

You are given a string?s?denoting the direction in which robots will move on command.?'L'?means the robot will move towards the left side or negative side of the number line, whereas?'R'?means the robot will move towards the right side or positive side of the number line.

If two robots collide, they will start moving in opposite directions.

Return?the sum of distances between all the?pairs of robots?d?seconds after?the command.?Since the sum can be very large, return it modulo?109?+ 7.

Note:

  • For two robots at the index?i?and?j, pair?(i,j)?and pair?(j,i)?are considered the same pair.

  • When robots collide, they?instantly change?their directions without wasting any time.

  • Collision happens?when two robots share the same place in a?moment.

    • For example, if a robot is positioned in 0 going to the right and another is positioned in 2 going to the left, the next second they'll be both in 1 and they will change direction and the next second the first one will be in 0, heading left, and another will be in 2, heading right.

    • For example,?if a robot is positioned in 0 going to the right and another is positioned in 1?going to the left, the next second the first one will be in 0, heading left, and another will be in 1, heading right.

?

Example 1:

Input: nums = [-2,0,2], s = "RLL", d = 3

Output: 8

Explanation:?

After 1 second, the positions are [-1,-1,1]. Now, the robot at index 0 will move left, and the robot at index 1 will move right.?

After 2 seconds, the positions are [-2,0,0]. Now, the robot at index 1 will move left, and the robot at index 2 will move right.?

After 3 seconds, the positions are [-3,-1,1]. The distance between the robot at index 0 and 1 is abs(-3 - (-1)) = 2. The distance between the robot at index 0 and 2 is abs(-3 - 1) = 4. The distance between the robot at index 0 and 1 is abs(-1 - 1) = 2.?

The sum of the pairs of all distances = 2 + 4 + 2 = 8.

Example 2:

Input: nums = [1,0], s = "RL", d = 2

Output: 5

Explanation: After 1 second, the positions are [2,-1]. After 2 seconds, the positions are [3,-2]. The distance between the two robots is abs(-2 - 3) = 5.

?

Constraints:

  • 2 <= nums.length <= 105

  • -2 * 109?<= nums[i] <= 2 * 109

  • 0 <= d <= 109

  • nums.length == s.length?

  • s?consists of 'L' and 'R' only

  • nums[i]?will be unique.

    可以不考慮機(jī)器人的位置,因?yàn)槭怯?jì)算所有的機(jī)器人的距離之和的。

    另外就是要累計(jì)求出來(lái)這個(gè)的數(shù)值,才是最終的答案。即可;

Runtime:?15 ms, faster than?87.18%?of?Java?online submissions for?Movement of Robots.

Memory Usage:?55 MB, less than?52.41%?of?Java?online submissions for?Movement of Robots.


LeetCode 2731. Movement of Robots的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
武威市| 体育| 靖江市| 霍邱县| 正定县| 鱼台县| 呼图壁县| 宜丰县| 扎鲁特旗| 巨鹿县| 永善县| 西昌市| 南靖县| 承德市| 桦甸市| 鄂州市| 安溪县| 竹北市| 苍溪县| 四平市| 固原市| 闽侯县| 湘阴县| 肃宁县| 原平市| 安图县| 中山市| 宝兴县| 衡南县| 宣化县| 杭锦旗| 乌兰县| 吴江市| 印江| 井研县| 宜州市| 灵川县| 老河口市| 烟台市| 乾安县| 乌兰察布市|