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
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
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
class Solution: | |
# @param x, a float | |
# @param n, a integer | |
# @return a float | |
def pow(self, x, n): | |
if x == 0.0: | |
return 0.0 | |
if n < 0: | |
# Avoids arithmetic underflow | |
return 1.0/self.pow(x, -n) |
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
class Solution: | |
# @return a string | |
def longestCommonPrefix(self, strs): | |
# computes the LCP of the stringlist strs | |
if strs is None or len(strs) == 0: | |
return "" | |
return reduce(self.lcp, strs) | |
def lcp(self, str1, str2): |
NewerOlder