成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專(zhuān)欄INFORMATION COLUMN

2.leetcode唯一的摩斯密碼

XanaHopper / 2319人閱讀

摘要:題目自己的解決方法其他解決方法

1.題目
International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on.

For convenience, the full table for the 26 letters of the English alphabet is given below:

[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]

Now, given a list of words, each word can be written as a concatenation of the Morse code of each letter. For example, "cba" can be written as "-.-..--...", (which is the concatenation "-.-." + "-..." + ".-"). We"ll call such a concatenation, the transformation of a word.

Return the number of different transformations among all words we have.

Example:
Input: words = ["gin", "zen", "gig", "msg"]
Output: 2
Explanation: 
The transformation of each word is:
"gin" -> "--...-."
"zen" -> "--...-."
"gig" -> "--...--."
"msg" -> "--...--."

There are 2 different transformations, "--...-." and "--...--.".

自己的解決方法

class Solution:
    def uniqueMorseRepresentations(self, words: List[str]) -> int:
        final_set = set()
        mosLIst = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
        for word in words:
            temp = ""
            for i in word:
                temp += mosLIst[ord(i)-97]
            final_set.add(temp)
        return len(final_set)
Runtime: 36 ms, faster than 97.45% of Python3 online submissions for Unique Morse Code Words.
Memory Usage: 12.9 MB, less than 5.36% of Python3 online submissions for Unique Morse Code Words.

3.其他解決方法

const codes = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]

const getIdx = char => char.charCodeAt(0) - "a".charCodeAt(0)

var uniqueMorseRepresentations = function(words) {
    return words.map( word => word.split("")
                                 .map( char => codes[getIdx(char)])
                                 .join(""))
                .reduce((set, cur) => set.add(cur), new Set())
                .size
};

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

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/43449.html

相關(guān)文章

  • 2.leetcode唯一摩斯密碼

    摘要:題目自己的解決方法其他解決方法 1.題目International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: a maps to .-, b maps to -..., c maps to -.-., and...

    FreeZinG 評(píng)論0 收藏0
  • 中文摩斯密碼 - JavaScript庫(kù)

    摘要:中文摩斯密碼是一個(gè)使用編寫(xiě)的用于瀏覽器和環(huán)境的摩斯密碼庫(kù),可以支持,即支持中文的摩斯密碼解密和加密。安裝引入使用只有兩個(gè),名字為對(duì)于例子如下越過(guò)長(zhǎng)城,走向世界對(duì)于例子如下相關(guān)地址在線開(kāi)源地址 中文摩斯密碼 - Xmorse Xmorse?是一個(gè)使用 Javascript 編寫(xiě)的用于瀏覽器和 nodejs 環(huán)境的摩斯密碼庫(kù),可以支持 unicode,即支持中文的摩斯密碼解密和加密。 1...

    MadPecker 評(píng)論0 收藏0
  • 數(shù)據(jù)可用不可見(jiàn)!揭秘螞蟻區(qū)塊鏈摩斯安全計(jì)算平臺(tái)

    摘要:安全透明輕量的螞蟻區(qū)塊鏈摩斯安全計(jì)算基礎(chǔ)設(shè)施螞蟻摩斯依托螞蟻金融科技平臺(tái),結(jié)合區(qū)塊鏈技術(shù),將復(fù)雜的隱私保護(hù)與密碼學(xué)算法透明化產(chǎn)品化,提供安全發(fā)布安全模型安全統(tǒng)計(jì)安全查詢(xún)安全腳本等核心功能。 摘要:?螞蟻區(qū)塊鏈摩斯安全計(jì)算平臺(tái)針對(duì)數(shù)據(jù)安全信任、個(gè)人隱私保護(hù)以及數(shù)據(jù)基礎(chǔ)設(shè)施不足等痛點(diǎn),秉持?jǐn)?shù)據(jù)可用不可見(jiàn)和將計(jì)算移動(dòng)到數(shù)據(jù)端的原則,借助區(qū)塊鏈、密碼學(xué)、隱私保護(hù)、安全多方計(jì)算、可信計(jì)算等前沿...

    zhisheng 評(píng)論0 收藏0
  • 花樣招聘面試題

    摘要:由于我們得到摩斯密碼沒(méi)有空格隔開(kāi),所以解密后有可能不止一種。完整的代碼得到結(jié)果如下,根據(jù)圖片中的提示,該單詞與面試有關(guān),那么應(yīng)該是無(wú)疑。上面的代碼我們用了層嵌套循環(huán),確實(shí)有點(diǎn)多,但是只有條件成立,才會(huì)進(jìn)入深層的循環(huán)。 殘缺的地圖 今天在微信群里面看到一張招聘圖片,如下 showImg(https://segmentfault.com/img/bVbhvww?w=600&h=600); ...

    e10101 評(píng)論0 收藏0
  • RhykeJS——專(zhuān)為開(kāi)啟“實(shí)驗(yàn)室功能”手勢(shì)密碼庫(kù)

    摘要:預(yù)覽地址項(xiàng)目地址初衷在前端業(yè)務(wù)上生產(chǎn)的時(shí)候,可能仍然有部分功能需要被隱藏,只有達(dá)成特定的條件才能夠顯示,這些功能可以被稱(chēng)作為實(shí)驗(yàn)室功能。參考了上述多種做法,提出了使用摩斯電碼節(jié)奏作為手勢(shì)密碼,開(kāi)啟實(shí)驗(yàn)室功能的想法。 showImg(https://segmentfault.com/img/bVYHYF?w=922&h=271); 預(yù)覽地址:https://jrainlau.github...

    用戶(hù)83 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<