View gist:4c8417c32da12a3125338087e4ad89a1
This file contains 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
# Content of a test file | |
CREATE TABLE t1 (a VARBINARY(128)) CHARACTER SET utf32; | |
INSERT INTO t1 VALUES ('South Carolina, Vermont, New Jersey, New Mexico, Wisconsin, Missouri, Delaware'); | |
CREATE TABLE t2 (b SET('South Carolina', 'Vermont', 'Texas', 'New Mexico', 'Wisconsin', 'Missouri', 'Delaware', 'Wyoming', 'New Jersey', 'Maryland', 'Illinois', 'New York')) CHARACTER SET utf32; | |
--error WARN_DATA_TRUNCATED | |
INSERT INTO t2 SELECT * FROM t1; | |
SELECT * FROM t2; | |
DROP TABLE t1; | |
DROP TABLE t2; |
View algorithm_string_longest_common_prefix.java
This file contains 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
public class Solution { | |
public String longestCommonPrefix(String[] strs) { | |
int leng = strs.length; | |
if (leng == 0) return ""; | |
else if (leng == 1) return strs[0]; | |
// check the minimum length among all strings | |
int minLen = strs[0].length(); | |
String minStr = strs[0]; | |
for (int i = 1; i < leng; i++) { |
View algorithm_math_romanr_to_integer.java
This file contains 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
public class Solution { | |
public int romanToInt(String s) { | |
int len = s.length(); | |
s = s + " "; | |
int res = 0; | |
for (int i = 0; i < len; i++) { | |
char ch = s.charAt(i); | |
char nxCh = s.charAt(i+1); | |
View algorithm_math_romanr_to_integer.py
This file contains 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
class Solution(object): | |
def romanToInt(self, s): | |
""" | |
:type s: str | |
:rtype: int | |
""" | |
leng = len(s) | |
s = s + ' ' | |
i = 0 |
View algorithm_math_integer_to_roman.java
This file contains 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
public class Solution { | |
public String intToRoman(int num) { | |
String mapping[][] = { | |
{"", "M", "MM", "MMM"}, | |
{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, | |
{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, | |
{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}, | |
}; | |
StringBuilder res = new StringBuilder(); |
View algorithm_math_integer_to_roman.py
This file contains 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
class Solution(object): | |
def intToRoman(self, num): | |
""" | |
:type num: int | |
:rtype: str | |
""" | |
# mp = {scale: {number : roman}} | |
mp = {1: ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'], | |
10: ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'], |
View algorithm_search_container_with_most_water.py
This file contains 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
class Solution(object): | |
def maxArea(self, height): | |
""" | |
:type height: List[int] | |
:rtype: int | |
""" | |
leng = len(height) | |
if leng <= 1: 0 | |
res = 0 |
View algorithm_search_container_with_most_water.java
This file contains 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
public class Solution { | |
public int maxArea(int[] height) { | |
int len = height.length; | |
if (len <= 1) return 0; | |
int left = 0; | |
int right = len - 1; | |
int res = 0; | |
while (left != right) { |
View algorithm_math_palindrome_number.java
This file contains 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
public class Solution { | |
public boolean isPalindrome(int x) { | |
if (x < 0) return false; | |
else if (x >= 0 && x < 10) return true; | |
int originalX = x; | |
int reversedX = 0; | |
while (x > 0) { | |
reversedX = reversedX * 10 + x % 10; | |
x /= 10; |
View algorithm_math_palindrome_number.py
This file contains 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
class Solution(object): | |
def isPalindrome(self, x): | |
""" | |
:type x: int | |
:rtype: bool | |
""" | |
if x < 0: return False | |
elif x >= 0 and x < 10: return True | |
originalX = x |
NewerOlder