ARTS Week 17

February 17, 2020 ~ February 23, 2020

Algorithm

Problem 205.Isomorphic Strings (isomorphic string) Title Link

Description Title: Given two strings s and t, can be determined whether the character obtained by replacing t from s. The order can not be changed, while not allowing the two characters are mapped to the same character, but allows a character is mapped to its own. For example as follows:
the Input: S = "Egg", T = "the Add"
the Output: to true

Input: s = "foo", t = "bar"
Output: false

Ideas for: mapping relationship can be established through the dictionary. Because the two characters are not allowed mapped to the same character, it is necessary to check whether the character to be mapped has occurred in the value of the dictionary. To conclude is: if the key has appeared in dictionary key, then checked whether the mapping relationship, if not satisfied, compared False. Satisfy continue to traverse; if the key does not appear in the dictionary key, check the character to be mapped is already present in the dictionary value, if occurred, on the False, if not then update the existing mappings. Until the end of the traverse True,

Code via the following

class Solution:
    def isIsomorphic(self, s: str, t: str) -> bool:
        char_map = {}
        res = True
        for i in range(len(s)):
            if (s[i] not in char_map) and (t[i] not in char_map.values()):
                char_map[s[i]] = t[i]
            elif (s[i] not in char_map) and (t[i] in char_map.values()):
                res = False
                break
            else:
                if char_map[s[i]] != t[i]:
                    res = False
                    break
        return res

Review

Review each week to continue programmers need to know 97 things (English name: 97 Things Every Programmer Should Know) . Original link . Below are 5 small for this week:

  • How to learn to say "Hello World" (Learn to Say "Hello, World") description link
    When we learn a new programming language or a new language, we need to learn the basic content is "Hello World".
  • Let your project speak for themselves (Let Your Project Speak for Itself) description link
    need to give a sound project. So that there is a problem when the project can be done by e-mail or instant messaging to inform developers know the latest situation, at the same time, you can set different levels according to the urgency of the project, like a red light and yellow light than traffic lights.
  • The linker is not a magic program (The Linker Is not a Magical Program ) description link
    Many people in the source code becomes executable file compiled by the linking process, often encounter some warnings, such as: a variable linker say is defined more than once, the linker say that a variable is not defined. It is unwise to ignore these warnings, although the link is likely to solve these problems, but not all of the warnings can be resolved, the better approach is to solve these problems themselves.
  • Life (The Longevity of Interim Solutions) temporary solution description link
    usually in order to quickly resolve some of the immediate problems that may need to develop a temporary tool / program to resolve the emergency. However, we still need real solutions to solve this problem, if not resolved, then the temporary solution will be more and more, leading to internal projects increased complexity, maintainability decline. Therefore, when we use a temporary solution, it should be adopted as soon as possible formal solution to replace it, but not always keep it.
  • Make the interface easy to use correctly (Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly) description link
    interface development software development is one of the most common tasks, whether it is the user interface, the interface and functionality, but also the class or interface library interface Wait. Good user interfaces are easy to use and modify. In short, the principle is: there is an interface for the convenience of users, rather than implementors of the interface.

Tip

C / C ++ as the static modifier modification function of the role: to avoid conflicts scoped, a function can only appear in one file.

Share

This week, I spent a lot of time in infrastructure and toss some silly things, because not too familiar with, consume too much time. The original really intend to do the results did not do much.

Guess you like

Origin www.cnblogs.com/mengxinayan/p/12348675.html