Check Permutation: Given two strings, write a method to decide if one is a permutation of the other. p.90
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
defcheck_permutation(s1, s2): iflen(s1) != len(s2): returnFalse sd1 = {} for i in s1: if sd1.get(i): sd1[i] = sd1[i] + 1 else: sd1[i] = 1 for j in s2: if sd1.get(j): if sd1.get(j) > 0: sd1[i] = sd1[i] - 1 else: returnFalse else: returnFalse returnTrue
samples
dad, bda
abc, bca
sss, sss
sas, ssa
abcd, abc
bbba, bbbb
URLify: Write a method to replace all spaces in a string with ‘%20’. You may assume that the string has sufficient space at the end to hold the additional characters, and that you are given the “true” length of the string. (Note: If implementing in Java, please use a character array so that you can perform this operation in place.)
錯誤1: 忘記回傳值
Palindrome Permutation: Given a string, write a function to check if it is a permutation of a palin-drome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import copy
defpalindrome(input): input = input.lower() char_dict = {} for c ininput: if c != " ": if char_dict.get(c): char_dict.pop(c) else: char_dict[c] = 1 iflen(char_dict) > 1: returnFalse returnTrue
錯誤1: 沒有考慮到大小寫問題
One Away: There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edit (or zero edits) away.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
defone_edit(str_a, str_b): iflen(str_a) - len(str_b) == -1: for c in str_a: if c notin str_b: returnFalse eliflen(str_a) - len(str_b) == 1: for c in str_b: if c notin str_a: returnFalse eliflen(str_a) - len(str_b) == 0: counter = 0 for c in str_a: if c notin str_b: counter +=1 if counter > 1: returnFalse else: returnFalse returnTrue
Posted Updated a few seconds read (About 58 words)
systemctl disable [servicename] sudo trash /etc/systemd/system/[servicename] sudo trash /etc/systemd/system/[servicename] # and symlinks that might be related sudo trash /usr/lib/systemd/system/[servicename] sudo trash /usr/lib/systemd/system/[servicename] # and symlinks that might be related systemctl daemon-reload systemctl reset-failedbash
直接用dpkg安裝套件,如果有缺少的相依套件,之後使用apt install就會顯示E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).錯誤,必須要手動解決相依性問提
Quick instructions to create a trivial local archive with apt-ftparchive We use /var/lib/mydebs as the example location
Create the directory
mkdir -p /var/lib/mydebs Every time you put new files in the directory, you'll have to scan the directory and update:
cd /var/lib/mydebs apt-ftparchive packages . > Packages apt-ftparchive release . > Release Add this line to /etc/apt/sources.list
deb [allow-insecure=yes] file:/var/lib/mydebs ./ Now you can install the package normally. If apt-get asks "Install these packages without verification?", answer "Y" to install. That's because this local repository is not signed.
$ sudo apt-get install gparted=0.16.1-1 Reading package lists... Done Building dependency tree Reading state information... Done gparted is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 265 not upgraded.
Posted Updated a few seconds read (About 58 words)