Skip to content

Instantly share code, notes, and snippets.

View rdtr's full-sized avatar

Norio Akagi rdtr

View GitHub Profile
# 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;
@rdtr
rdtr / algorithm_string_longest_common_prefix.java
Last active January 6, 2016 17:12
algorithm_string_longest_common_prefix
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++) {
@rdtr
rdtr / algorithm_math_romanr_to_integer.java
Last active January 5, 2016 17:58
algorithm_math_romanr_to_integer.java
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);
@rdtr
rdtr / algorithm_math_romanr_to_integer.py
Created January 5, 2016 17:41
algorithm_math_romanr_to_integer.py
class Solution(object):
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
leng = len(s)
s = s + ' '
i = 0
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();
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'],
class Solution(object):
def maxArea(self, height):
"""
:type height: List[int]
:rtype: int
"""
leng = len(height)
if leng <= 1: 0
res = 0
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) {
@rdtr
rdtr / algorithm_math_palindrome_number.java
Created December 22, 2015 00:31
algorithm_math_palindrome_number.java
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;
@rdtr
rdtr / algorithm_math_palindrome_number.py
Created December 22, 2015 00:29
algorithm_math_palindrome_number.py
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