網路城邦
回本城市首頁 卡蜜拉童創奇幻仙境
市長:cAmilla  副市長:
加入本城市推薦本城市加入我的最愛訂閱最新文章
udn城市文學創作其他【卡蜜拉童創奇幻仙境】城市/討論區/
討論區Children Literature TTP 兒童文學師資培訓 字體:
看回應文章  上一個討論主題 回文章列表 下一個討論主題
Leetcode Zone
 瀏覽1,278|回應1推薦0

cAmilla
等級:8
留言加入好友
Python 3
class Solution:
    def numUniqueEmails(self, emails: List[str]) -> int

Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'.
  • For example, in "alice@leetcode.com""alice" is the local name, and "leetcode.com" is the domain name.

If you add periods '.' between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. Note that this rule does not apply to domain names.

  • For example, "alice.z@leetcode.com" and "alicez@leetcode.com" forward to the same email address.

If you add a plus '+' in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered. Note that this rule does not apply to domain names.

  • For example, "m.y+name@email.com" will be forwarded to "my@email.com".

It is possible to use both of these rules at the same time.

Given an array of strings emails where we send one email to each emails[i], return the number of different addresses that actually receive mails.


cAmilla
Love, Peace, Hope & Future!

本文於 修改第 1 次
回應 回應給此人 推薦文章 列印 加入我的文摘

引用
引用網址:https://city.udn.com/forum/trackback.jsp?no=55112&aid=7163987
 回應文章
Verifying an Alien Dictionary
推薦0


cAmilla
等級:8
留言加入好友

 
Verifying an Alien Dictionary
Solution

In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.

Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographically in this alien language.

 

Example 1:

Input: words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"
Output: true
Explanation: As 'h' comes before 'l' in this language, then the sequence is sorted.

Example 2:

Input: words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"
Output: false
Explanation: As 'd' comes after 'l' in this language, then words[0] > words[1], hence the sequence is unsorted.

Example 3:

Input: words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"
Output: false
Explanation: The first three characters "app" match, and the second string is shorter (in size.) According to lexicographical rules "apple" > "app", because 'l' > '∅', where '∅' is defined as the blank character which is less than any other character (More info). 

Constraints:

  • 1 <= words="" length="" 100="" code="">
  • 1 <= words="" i="" length="" 20="" code="">
  • order.length == 26
  • All characters in words[i] and order are English lowercase letters.

Python

class Solution(object):

    def isAlienSorted(self, words, order):

        """

        :type words: List[str]

        :type order: str

        :rtype: bool

        """ 



本文於 修改第 1 次
回應 回應給此人 推薦文章 列印 加入我的文摘
引用網址:https://city.udn.com/forum/trackback.jsp?no=55112&aid=7163988