From 4cc7c8cc70d482632de8d06459a8ff46647fa12a Mon Sep 17 00:00:00 2001 From: devenperez Date: Sun, 8 Jan 2023 09:19:00 -0500 Subject: [PATCH] Removing old questions Removed questions uploaded using an old version of LeetHub Questions 2,3,4,19,36,141,206 --- .../141-linked-list-cycle.py | 22 -------- 141-linked-list-cycle/NOTES.md | 1 - 141-linked-list-cycle/README.md | 40 ------------- .../19-remove-nth-node-from-end-of-list.py | 32 ----------- 19-remove-nth-node-from-end-of-list/NOTES.md | 1 - 19-remove-nth-node-from-end-of-list/README.md | 34 ----------- 2-add-two-numbers/2-add-two-numbers.py | 38 ------------- 2-add-two-numbers/NOTES.md | 1 - 2-add-two-numbers/README.md | 33 ----------- .../206-reverse-linked-list.py | 20 ------- 206-reverse-linked-list/NOTES.md | 1 - 206-reverse-linked-list/README.md | 32 ----------- ...-substring-without-repeating-characters.py | 26 --------- .../NOTES.md | 1 - .../README.md | 33 ----------- 36-valid-sudoku/36-valid-sudoku.py | 48 ---------------- 36-valid-sudoku/README.md | 56 ------------------- .../4-median-of-two-sorted-arrays.py | 47 ---------------- 4-median-of-two-sorted-arrays/NOTES.md | 1 - 4-median-of-two-sorted-arrays/README.md | 31 ---------- 20 files changed, 498 deletions(-) delete mode 100644 141-linked-list-cycle/141-linked-list-cycle.py delete mode 100644 141-linked-list-cycle/NOTES.md delete mode 100644 141-linked-list-cycle/README.md delete mode 100644 19-remove-nth-node-from-end-of-list/19-remove-nth-node-from-end-of-list.py delete mode 100644 19-remove-nth-node-from-end-of-list/NOTES.md delete mode 100644 19-remove-nth-node-from-end-of-list/README.md delete mode 100644 2-add-two-numbers/2-add-two-numbers.py delete mode 100644 2-add-two-numbers/NOTES.md delete mode 100644 2-add-two-numbers/README.md delete mode 100644 206-reverse-linked-list/206-reverse-linked-list.py delete mode 100644 206-reverse-linked-list/NOTES.md delete mode 100644 206-reverse-linked-list/README.md delete mode 100644 3-longest-substring-without-repeating-characters/3-longest-substring-without-repeating-characters.py delete mode 100644 3-longest-substring-without-repeating-characters/NOTES.md delete mode 100644 3-longest-substring-without-repeating-characters/README.md delete mode 100644 36-valid-sudoku/36-valid-sudoku.py delete mode 100644 36-valid-sudoku/README.md delete mode 100644 4-median-of-two-sorted-arrays/4-median-of-two-sorted-arrays.py delete mode 100644 4-median-of-two-sorted-arrays/NOTES.md delete mode 100644 4-median-of-two-sorted-arrays/README.md diff --git a/141-linked-list-cycle/141-linked-list-cycle.py b/141-linked-list-cycle/141-linked-list-cycle.py deleted file mode 100644 index e649457..0000000 --- a/141-linked-list-cycle/141-linked-list-cycle.py +++ /dev/null @@ -1,22 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution(object): - def hasCycle(self, head): - """ - :type head: ListNode - :rtype: bool - """ - if head == None or head.next == None: return False - myDict = {head: 0} - point = head - while True: - point = point.next - if point == None: return False - if myDict.get(point) == None: - myDict[point] = 0 - else: - return True \ No newline at end of file diff --git a/141-linked-list-cycle/NOTES.md b/141-linked-list-cycle/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/141-linked-list-cycle/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/141-linked-list-cycle/README.md b/141-linked-list-cycle/README.md deleted file mode 100644 index 73491c5..0000000 --- a/141-linked-list-cycle/README.md +++ /dev/null @@ -1,40 +0,0 @@ -

141. Linked List Cycle

Easy


Given head, the head of a linked list, determine if the linked list has a cycle in it.

- -

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.

- -

Return true if there is a cycle in the linked list. Otherwise, return false.

- -

 

-

Example 1:

- -
Input: head = [3,2,0,-4], pos = 1
-Output: true
-Explanation: There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed).
-
- -

Example 2:

- -
Input: head = [1,2], pos = 0
-Output: true
-Explanation: There is a cycle in the linked list, where the tail connects to the 0th node.
-
- -

Example 3:

- -
Input: head = [1], pos = -1
-Output: false
-Explanation: There is no cycle in the linked list.
-
- -

 

-

Constraints:

- - - -

 

-

Follow up: Can you solve it using O(1) (i.e. constant) memory?

-
\ No newline at end of file diff --git a/19-remove-nth-node-from-end-of-list/19-remove-nth-node-from-end-of-list.py b/19-remove-nth-node-from-end-of-list/19-remove-nth-node-from-end-of-list.py deleted file mode 100644 index 35dffe5..0000000 --- a/19-remove-nth-node-from-end-of-list/19-remove-nth-node-from-end-of-list.py +++ /dev/null @@ -1,32 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution(object): - def removeNthFromEnd(self, head, n): - """ - :type head: ListNode - :type n: int - :rtype: ListNode - """ - - # Get length - counterNode = head - length = 0 - while counterNode != None: - counterNode = counterNode.next - length = length + 1 - - # Readjust - if length == 1: return None - if length == n: return head.next - nodeBefore = head - for i in range(length - n - 1): - nodeBefore = nodeBefore.next - if n == 1: - nodeBefore.next = None - else: - nodeBefore.next = nodeBefore.next.next - - return head \ No newline at end of file diff --git a/19-remove-nth-node-from-end-of-list/NOTES.md b/19-remove-nth-node-from-end-of-list/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/19-remove-nth-node-from-end-of-list/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/19-remove-nth-node-from-end-of-list/README.md b/19-remove-nth-node-from-end-of-list/README.md deleted file mode 100644 index 8d4110a..0000000 --- a/19-remove-nth-node-from-end-of-list/README.md +++ /dev/null @@ -1,34 +0,0 @@ -

19. Remove Nth Node From End of List

Medium


Given the head of a linked list, remove the nth node from the end of the list and return its head.

- -

 

-

Example 1:

- -
Input: head = [1,2,3,4,5], n = 2
-Output: [1,2,3,5]
-
- -

Example 2:

- -
Input: head = [1], n = 1
-Output: []
-
- -

Example 3:

- -
Input: head = [1,2], n = 1
-Output: [1]
-
- -

 

-

Constraints:

- - - -

 

-

Follow up: Could you do this in one pass?

-
\ No newline at end of file diff --git a/2-add-two-numbers/2-add-two-numbers.py b/2-add-two-numbers/2-add-two-numbers.py deleted file mode 100644 index d86725b..0000000 --- a/2-add-two-numbers/2-add-two-numbers.py +++ /dev/null @@ -1,38 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution(object): - def addTwoNumbers(self, l1, l2): - """ - :type l1: ListNode - :type l2: ListNode - :rtype: ListNode - """ - sum = ListNode((l1.val + l2.val) % 10) - carry = (l1.val + l2.val) / 10 - follow = sum - num1 = l1.next - num2 = l2.next - while num1 != None or num2 != None or carry > 0: - if num1 == None and num2 == None: - follow.next = ListNode(carry) - carry = 0 - elif num1 == None: - follow.next = ListNode((num2.val + carry) % 10) - follow = follow.next - carry = (num2.val + carry) / 10 - num2 = num2.next - elif num2 == None: - follow.next = ListNode((num1.val + carry) % 10) - follow = follow.next - carry = (num1.val + carry) / 10 - num1 = num1.next - else: - follow.next = ListNode((num1.val + num2.val + carry) % 10) - follow = follow.next - carry = (num1.val + num2.val + carry) / 10 - num1 = num1.next - num2 = num2.next - return sum \ No newline at end of file diff --git a/2-add-two-numbers/NOTES.md b/2-add-two-numbers/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/2-add-two-numbers/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/2-add-two-numbers/README.md b/2-add-two-numbers/README.md deleted file mode 100644 index 23f654a..0000000 --- a/2-add-two-numbers/README.md +++ /dev/null @@ -1,33 +0,0 @@ -

2. Add Two Numbers

Medium


You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

- -

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

- -

 

-

Example 1:

- -
Input: l1 = [2,4,3], l2 = [5,6,4]
-Output: [7,0,8]
-Explanation: 342 + 465 = 807.
-
- -

Example 2:

- -
Input: l1 = [0], l2 = [0]
-Output: [0]
-
- -

Example 3:

- -
Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
-Output: [8,9,9,9,0,0,0,1]
-
- -

 

-

Constraints:

- - -
\ No newline at end of file diff --git a/206-reverse-linked-list/206-reverse-linked-list.py b/206-reverse-linked-list/206-reverse-linked-list.py deleted file mode 100644 index 577527c..0000000 --- a/206-reverse-linked-list/206-reverse-linked-list.py +++ /dev/null @@ -1,20 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution(object): - def reverseList(self, head): - """ - :type head: ListNode - :rtype: ListNode - """ - if head == None: return None - if head.next == None: return head - - reversedHead = ListNode(head.val) - oldNode = head.next - while oldNode != None: - reversedHead = ListNode(oldNode.val, reversedHead) - oldNode = oldNode.next - return reversedHead \ No newline at end of file diff --git a/206-reverse-linked-list/NOTES.md b/206-reverse-linked-list/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/206-reverse-linked-list/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/206-reverse-linked-list/README.md b/206-reverse-linked-list/README.md deleted file mode 100644 index 8343480..0000000 --- a/206-reverse-linked-list/README.md +++ /dev/null @@ -1,32 +0,0 @@ -

206. Reverse Linked List

Easy


Given the head of a singly linked list, reverse the list, and return the reversed list.

- -

 

-

Example 1:

- -
Input: head = [1,2,3,4,5]
-Output: [5,4,3,2,1]
-
- -

Example 2:

- -
Input: head = [1,2]
-Output: [2,1]
-
- -

Example 3:

- -
Input: head = []
-Output: []
-
- -

 

-

Constraints:

- - - -

 

-

Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both?

-
\ No newline at end of file diff --git a/3-longest-substring-without-repeating-characters/3-longest-substring-without-repeating-characters.py b/3-longest-substring-without-repeating-characters/3-longest-substring-without-repeating-characters.py deleted file mode 100644 index df1d51b..0000000 --- a/3-longest-substring-without-repeating-characters/3-longest-substring-without-repeating-characters.py +++ /dev/null @@ -1,26 +0,0 @@ -class Solution(object): - def lengthOfLongestSubstring(self, s): - """ - :type s: str - :rtype: int - """ - letters = [x for x in s] - longestLength = 1 - - if len(letters) == 0: return 0 - - for i in range(len(letters)): - dictionary = {} - for j in range(i, len(letters)): - if dictionary.get(letters[j]) == None: - dictionary[letters[j]] = 0 - else: - if j-i > longestLength: - longestLength = j-i - break - - if j == len(letters) - 1: - if j-i+1 > longestLength: - longestLength = j-i+1 - return longestLength - return longestLength \ No newline at end of file diff --git a/3-longest-substring-without-repeating-characters/NOTES.md b/3-longest-substring-without-repeating-characters/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/3-longest-substring-without-repeating-characters/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/3-longest-substring-without-repeating-characters/README.md b/3-longest-substring-without-repeating-characters/README.md deleted file mode 100644 index dee258d..0000000 --- a/3-longest-substring-without-repeating-characters/README.md +++ /dev/null @@ -1,33 +0,0 @@ -

3. Longest Substring Without Repeating Characters

Medium


Given a string s, find the length of the longest substring without repeating characters.

- -

 

-

Example 1:

- -
Input: s = "abcabcbb"
-Output: 3
-Explanation: The answer is "abc", with the length of 3.
-
- -

Example 2:

- -
Input: s = "bbbbb"
-Output: 1
-Explanation: The answer is "b", with the length of 1.
-
- -

Example 3:

- -
Input: s = "pwwkew"
-Output: 3
-Explanation: The answer is "wke", with the length of 3.
-Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
-
- -

 

-

Constraints:

- - -
\ No newline at end of file diff --git a/36-valid-sudoku/36-valid-sudoku.py b/36-valid-sudoku/36-valid-sudoku.py deleted file mode 100644 index 0c23de5..0000000 --- a/36-valid-sudoku/36-valid-sudoku.py +++ /dev/null @@ -1,48 +0,0 @@ -class Solution(object): - def isValidSudoku(self, board): - """ - :type board: List[List[str]] - :rtype: bool - """ - # Check horizontals - for i in range(len(board)): - inRow = [False] * 10 - - for j in range(len(board[i])): - if board[i][j] == ".": - continue - else: - if inRow[int(board[i][j])]: - return False - else: - inRow[int(board[i][j])] = True - - - # Check verticals - for j in range(len(board[0])): - inColumn = [False] * 10 - - for i in range(len(board)): - if board[i][j] == ".": - continue - else: - if inColumn[int(board[i][j])]: - return False - else: - inColumn[int(board[i][j])] = True - - # Check boxes - for boxI in range(3): - for boxJ in range(3): - inBox = [False] * 10 - for i in range(3): - for j in range(3): - if board[(boxI * 3) + i][(boxJ * 3) + j] == ".": - continue - else: - if inBox[int(board[(boxI * 3) + i][(boxJ * 3) + j])]: - return False - else: - inBox[int(board[(boxI * 3) + i][(boxJ * 3) + j])] = True - - return True \ No newline at end of file diff --git a/36-valid-sudoku/README.md b/36-valid-sudoku/README.md deleted file mode 100644 index 0a925bb..0000000 --- a/36-valid-sudoku/README.md +++ /dev/null @@ -1,56 +0,0 @@ -

36. Valid Sudoku

Medium


Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

- -
    -
  1. Each row must contain the digits 1-9 without repetition.
  2. -
  3. Each column must contain the digits 1-9 without repetition.
  4. -
  5. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
  6. -
- -

Note:

- - - -

 

-

Example 1:

- -
Input: board = 
-[["5","3",".",".","7",".",".",".","."]
-,["6",".",".","1","9","5",".",".","."]
-,[".","9","8",".",".",".",".","6","."]
-,["8",".",".",".","6",".",".",".","3"]
-,["4",".",".","8",".","3",".",".","1"]
-,["7",".",".",".","2",".",".",".","6"]
-,[".","6",".",".",".",".","2","8","."]
-,[".",".",".","4","1","9",".",".","5"]
-,[".",".",".",".","8",".",".","7","9"]]
-Output: true
-
- -

Example 2:

- -
Input: board = 
-[["8","3",".",".","7",".",".",".","."]
-,["6",".",".","1","9","5",".",".","."]
-,[".","9","8",".",".",".",".","6","."]
-,["8",".",".",".","6",".",".",".","3"]
-,["4",".",".","8",".","3",".",".","1"]
-,["7",".",".",".","2",".",".",".","6"]
-,[".","6",".",".",".",".","2","8","."]
-,[".",".",".","4","1","9",".",".","5"]
-,[".",".",".",".","8",".",".","7","9"]]
-Output: false
-Explanation: Same as Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid.
-
- -

 

-

Constraints:

- - -
\ No newline at end of file diff --git a/4-median-of-two-sorted-arrays/4-median-of-two-sorted-arrays.py b/4-median-of-two-sorted-arrays/4-median-of-two-sorted-arrays.py deleted file mode 100644 index 2be79c0..0000000 --- a/4-median-of-two-sorted-arrays/4-median-of-two-sorted-arrays.py +++ /dev/null @@ -1,47 +0,0 @@ -class Solution(object): - def findMedianSortedArrays(self, nums1, nums2): - """ - :type nums1: List[int] - :type nums2: List[int] - :rtype: float - """ - - # Variables - totalLength = len(nums1) + len(nums2) - goalIndex = (totalLength / 2.0) - 0.5 # Index of median - num1Index = 0 - num2Index = 0 - median = 0.0 - - # Go through arrays simultaniously - # Indexing up only on the lower number - # Stop after we hit "goalIndex" - for i in range(int(goalIndex + 1.5)): - # OOB Checks - if num1Index >= len(nums1): - lowestNum2 = nums2[num2Index] - lowestNum1 = lowestNum2 + 1 - elif num2Index >= len(nums2): - lowestNum1 = nums1[num1Index] - lowestNum2 = lowestNum1 + 1 - else: - - # QOL variables - lowestNum1 = nums1[num1Index] - lowestNum2 = nums2[num2Index] - - # Index up logic - if lowestNum1 <= lowestNum2: - num1Index += 1 - if i == int(goalIndex) or i == round(goalIndex): - median += lowestNum1 - else: - num2Index += 1 - if i == int(goalIndex) or i == round(goalIndex): - median += lowestNum2 - - # Divide median by 2 if array is even - if int(goalIndex) != round(goalIndex): - median /= 2 - - return median \ No newline at end of file diff --git a/4-median-of-two-sorted-arrays/NOTES.md b/4-median-of-two-sorted-arrays/NOTES.md deleted file mode 100644 index 38c1374..0000000 --- a/4-median-of-two-sorted-arrays/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -​ \ No newline at end of file diff --git a/4-median-of-two-sorted-arrays/README.md b/4-median-of-two-sorted-arrays/README.md deleted file mode 100644 index c5835f0..0000000 --- a/4-median-of-two-sorted-arrays/README.md +++ /dev/null @@ -1,31 +0,0 @@ -

4. Median of Two Sorted Arrays

Hard


Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

- -

The overall run time complexity should be O(log (m+n)).

- -

 

-

Example 1:

- -
Input: nums1 = [1,3], nums2 = [2]
-Output: 2.00000
-Explanation: merged array = [1,2,3] and median is 2.
-
- -

Example 2:

- -
Input: nums1 = [1,2], nums2 = [3,4]
-Output: 2.50000
-Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
-
- -

 

-

Constraints:

- - -
\ No newline at end of file