J

Joshua

Leetcode: Nth Highest Salary, MySQL

Status: Accepted 14 / 14 test cases passed. Runtime: 484 ms, faster than 48.85% of MySQL online submissions Memory Usage: 0B, less than 100.00% of MySQL online submissions CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN SET N = N - 1; RETURN ( SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET N ); END ...
Read post

Leetcode: Longest Palindromic Substring, Python3

103 / 103 test cases passed Status: Accepted Runtime: 3732 ms (O(n2) solution) Memory Usage: 12.8 MB class Solution: def longestPalindrome(self, s: str) -> str: if len(s) <= 1: return s for i in range(len(s), 0, -1): # i: length of palendrome to check for for j in range(0, len(s) - i + 1): # j: starting position within s to check test = s[j:j+i] rev = test[::-1] if test == rev: retu...
Read post

Leetcode: Zigzag Conversion, Python3

1158 / 1158 test cases passed Status: Accepted Runtime: 56 ms (beats 86.64% of submissions) Memory Usage: 12.9 MB (beats 100.00% of submissions) class Solution: def convert(self, s: str, numRows: int) -> str: if numRows == 1: return s l = [] for r in range(numRows): l.append('') row = 0 it = -1 for i in range(len(s)): l[row] = l[row] + s[i] if i % (numRows-1) == 0: it = it*-1 ...
Read post

Leetcode: Longest Substring Without Repeating Characters, Python3

987 / 987 test cases passed. Status: Accepted Runtime: 56 ms (beats 85.87% of submissions) Memory Usage: 12.7 MB (beats 100.00% of submissions) class Solution: def lengthOfLongestSubstring(self, s: str) -> int: if len(s) <= 1: return len(s) start = 0 end = 1 longest = 1 seen = {s[start]: 0} while end < len(s): if s[end] not in seen: seen[s[end]] = end end += 1 if end - start...
Read post

Leetcode: Two Sum, Python3

29 / 29 test cases passed Status: Accepted Runtime: 48 ms (beats 91.25% of submissions Memory Usage: 14 MB (beats 65.58% of submissions) class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: numMap = {} for i in range(0, len(nums)): num = nums[i] complement = target - num if complement in numMap.keys(): return numMap[complement], i else: numMap[num] = i ...
Read post

Leetcode: Add Two Numbers, Python3

1563 / 1563 test cases passed Status: Accepted Runtime: 56 ms (beats 99.02% of submissions) Memory Usage: 12.6 MB (beats 100% of submissions) # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: cur, carry = self.addVals(l1.val, l2.val, 0) res = ListNode(cur) thisRes = res while((l1.next != None)...
Read post