国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

2.leetcode唯一的摩斯密碼

XanaHopper / 2315人閱讀

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

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
};

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/43449.html

相關文章

  • 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 評論0 收藏0
  • 中文摩斯密碼 - JavaScript庫

    摘要:中文摩斯密碼是一個使用編寫的用于瀏覽器和環境的摩斯密碼庫,可以支持,即支持中文的摩斯密碼解密和加密。安裝引入使用只有兩個,名字為對于例子如下越過長城,走向世界對于例子如下相關地址在線開源地址 中文摩斯密碼 - Xmorse Xmorse?是一個使用 Javascript 編寫的用于瀏覽器和 nodejs 環境的摩斯密碼庫,可以支持 unicode,即支持中文的摩斯密碼解密和加密。 1...

    MadPecker 評論0 收藏0
  • 數據可用不可見!揭秘螞蟻區塊鏈摩斯安全計算平臺

    摘要:安全透明輕量的螞蟻區塊鏈摩斯安全計算基礎設施螞蟻摩斯依托螞蟻金融科技平臺,結合區塊鏈技術,將復雜的隱私保護與密碼學算法透明化產品化,提供安全發布安全模型安全統計安全查詢安全腳本等核心功能。 摘要:?螞蟻區塊鏈摩斯安全計算平臺針對數據安全信任、個人隱私保護以及數據基礎設施不足等痛點,秉持數據可用不可見和將計算移動到數據端的原則,借助區塊鏈、密碼學、隱私保護、安全多方計算、可信計算等前沿...

    zhisheng 評論0 收藏0
  • 花樣招聘面試題

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

    e10101 評論0 收藏0
  • RhykeJS——專為開啟“實驗室功能”手勢密碼

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

    用戶83 評論0 收藏0

發表評論

0條評論

XanaHopper

|高級講師

TA的文章

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