亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

6leetcode機(jī)器移動

glumes / 2781人閱讀

1 題目

There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.

The move sequence is represented by a string, and the character moves[i] represents its ith move. Valid moves are R (right), L (left), U (up), and D (down). If the robot returns to the origin after it finishes all of its moves, return true. Otherwise, return false.

Note: The way that the robot is "facing" is irrelevant. "R" will always make the robot move to the right once, "L" will always make it move left, etc. Also, assume that the magnitude of the robot"s movement is the same for each move

## 2. 示例
Input: "UD"
Output: true 
Explanation: The robot moves up once, and then down once. All moves have the same magnitude, so it ended up at the origin where it started. Therefore, we return true
Input: "LL"
Output: false
Explanation: The robot moves left twice. It ends up two "moves" to the left of the origin. We return false because it is not at the origin at the end of its moves.
2. 解答
var judgeCircle = function(moves) {
    let x = 0, y = 0;
    for (let move of moves) {
        switch(move) {
            case "U": y++ ;break;
            case "D": y-- ;break;
            case "L": x-- ;break;
            case "R": x++ ;break;
        }
    }
    return x === 0 && y === 0
};
Runtime: 68 ms, faster than 86.60% of JavaScript online submissions
for Robot Return to Origin. Memory Usage: 36.7 MB, less than 40.71% of
JavaScript online submissions for Robot Return to Origin.
3. 其他解法
const judgeCircle = (moves) => {
    return moves.split("")
        .reduce((p, m) => [p[0] + (m === "R") - (m === "L"), p[1] + (m === "U") - (m === "D")], [0, 0])
        .join("") === "00"
};

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/103156.html

相關(guān)文章

  • 80VPS:日本/香港CN2服務(wù)器600元/月,E5/16G/1TB/20M帶寬

    摘要:商家提供最多的還是和獨(dú)立服務(wù)器租用,之前部落主要分享他的主機(jī),最近關(guān)注獨(dú)立服務(wù)器,比如中國香港,或者帶寬,可選防禦,現(xiàn)在系列香港或者日本服務(wù)器每月僅元起。本文於 2021-09-02 07:57 更新,部分內(nèi)容具有時效性,如有失效,請留言 80VPS怎麼樣,80VPS好不好,80VPS是一家成立較早的綜合性網(wǎng)絡(luò)產(chǎn)品服務(wù)商,提供的產(chǎn)品包括域名註冊、虛擬主機(jī)、VPS、雲(yún)服務(wù)器和獨(dú)立服務(wù)器租...

    wuyangchun 評論0 收藏0
  • 修羅云:成立兩周年特惠,有深港IPCL、香港HKT、廣州、中山、徐州、杭州、佛山等,最低6折起

    摘要:修羅雲(yún)成立兩周年了風(fēng)雨同舟,數(shù)次搬遷在此衷心感謝大家的陪伴官網(wǎng)優(yōu)惠碼首月折,續(xù)費(fèi)折廣州,中山,徐州,杭州,佛山獨(dú)立可用。修羅雲(yún)怎麼樣,修羅雲(yún)好不好,修羅雲(yún)是一家國內(nèi)老牌商家,商家以銷售NAT機(jī)器起家,國內(nèi)的中轉(zhuǎn)機(jī)相當(dāng)不錯,給的帶寬都非常高,如果你是移動或是教育網(wǎng)到國外速度非常慢,可以使用他家的中轉(zhuǎn)機(jī)拉一下,直接起飛的感覺,商家目前推出兩周年活動,他家一般很少有活動,本次優(yōu)惠為新購首月6折,續(xù)...

    Little_XM 評論0 收藏0
  • DMIT:國外高端VPS雲(yún)服務(wù)器特價(jià)優(yōu)惠,美國/香港/日本可選,高端CN2 GIA優(yōu)質(zhì)線路大帶寬不限

    摘要:內(nèi)存流量帶寬價(jià)格購買核不限月購買核不限月購買核不限月購買核不限月購買網(wǎng)絡(luò)測試查看含有美國洛杉磯標(biāo)籤的文章美國洛杉磯查看含有洛杉磯標(biāo)籤的文章洛杉磯高防日本東京查看含有香港標(biāo)籤的文章香港 最近站長整理了一下DMIT商家的CN2 GIA特價(jià)優(yōu)惠VPS雲(yún)服務(wù)器產(chǎn)品,主要是美國、香港、日本等地區(qū)的VPS雲(yún)服務(wù)器產(chǎn)品,線路方面依然非常優(yōu)質(zhì),有需要國外優(yōu)質(zhì)線路VPS雲(yún)服務(wù)器的朋友可以關(guān)注一...

    qqlcbb 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<