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): | |
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
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): | |
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 String longestPalindrome(String s) { | |
String res = ""; | |
int len = s.length(); | |
for (int i = 0; i < len; i++) { | |
if (2 * (len - i - 1) + 1 < res.length()) break; | |
String res1 = extendStr(s, i, i); | |
String res2 = extendStr(s, i, i+1); |
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 longestPalindrome(self, s): | |
ml, mr, mlen = 0, 0, 0 | |
ls = len(s) | |
for i in range(ls): | |
if 2*(ls-i-1)+1 < mlen: break | |
s1l, s1r = self.extendStr(s, i, i) | |
s2l, s2r = self.extendStr(s, i, i + 1) | |
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 double findMedianSortedArrays(int[] nums1, int[] nums2) { | |
int len1 = nums1.length; | |
int len2 = nums2.length; | |
int mid = (len1 + len2) / 2; | |
double res = 0.0; | |
res = 1.0 * findKthSmallest(nums1, 0, len1-1, nums2, 0, len2-1, mid); | |
if ((len1+len2) % 2 == 0) { | |
double res2 = 1.0 * findKthSmallest(nums1, 0, len1-1, nums2, 0, len2-1, mid-1); |
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 findMedianSortedArrays(self, nums1, nums2): | |
""" | |
:type nums1: List[int] | |
:type nums2: List[int] | |
:rtype: float | |
""" | |
len1, len2 = len(nums1), len(nums2) | |
leng = len1 + len2 | |
mid = leng / 2 |
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
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
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
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |