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) { |
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
#! usr/bin/python | |
# -*- coding: utf-8 -*- | |
def merge(lst1, lst2): | |
newlst = [] | |
while (len(lst1) > 0) and (len(lst2) > 0): | |
if lst1[0] < lst2[0]: | |
newlst.append(lst1.pop(0)) | |
else: | |
newlst.append(lst2.pop(0)) |
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
#! /usr/bin/python | |
# -*- coding: utf-8 -*- | |
def quick_sort(lst): | |
if len(lst) <= 1: | |
return lst | |
pivot = lst[0] | |
left, right = [], [] |
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; |
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 |
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 myAtoi(String str) { | |
int start = 0; | |
while (start < str.length() && str.charAt(start) == ' ') ++start; | |
if (start == str.length()) return 0; | |
int isPositive = 1; | |
if (str.charAt(start) == '-') { | |
isPositive = -1; | |
++start; |
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): | |
INTEGER_MAX = 2**31 | |
def reverse(self, x): | |
""" | |
:type x: int | |
:rtype: int | |
""" | |
isPositive = 1 | |
if x < 0: |
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 reverse(int x) { | |
int isPositive = 1; | |
if (x < 0) { | |
isPositive = -1; | |
x = -1 * x; | |
} | |
int sum = 0; | |
while (x > 0) { |
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 myAtoi(self, str): | |
str = str.strip() | |
negative = 1 | |
res = 0 | |
for i, ch in enumerate(str): | |
if i == 0 and ch == '-': | |
negative = -1 | |
continue |
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
def bucket_sort(lst): | |
dup_lst = lst[:] | |
ans_lst = [] | |
while dup_lst: | |
for i in range(len(dup_lst) - 1): | |
if dup_lst[i] > dup_lst[i+1]: | |
dup_lst[i], dup_lst[i+1] = dup_lst[i+1], dup_lst[i] | |
else: | |
ans_lst.append(dup_lst[-1]) |