Created
December 25, 2018 19:08
-
-
Save wszdwp/548ba353637097d990122079f0e4998e to your computer and use it in GitHub Desktop.
some smart code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shift a char | |
s[i] = (s[i] - 'a' + shift) % 26 + 'a'; | |
// flip upper to lower alphabeta or vice versa | |
// ascii code 'A': 65, 'a': 97 | |
// 97 - 32 = 65, flip 5th binary bit means minus or plus 32 | |
// bitwise XOR can flip to opposite bit: 1 ^ 1 = 0, 1 ^ 0 = 1, | |
s[i] ^= 32; | |
s[i] ^= 1 << 5; | |
// reg find | |
// condition "A.*A|LLL" , count of 'A' > 1 or count of continuous 'L' > 2 | |
// find() will find anyplace in s meet condition "A.*A|LLL" | |
Pattern.compile("A.*A|LLL").matcher(s).find(); | |
// match() method check the whole string s match | |
Pattern.compile("A.*A|LLL").matcher(s).match(); | |
// lookingAt() match prefix | |
Pattern.compile("A.*A|LLL").matcher(s).lookingAt(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment