Skip to content

Commit 3cc9e6a

Browse files
committed
addition of longest substring without repeating charqacters
1 parent 65e7174 commit 3cc9e6a

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

add_two_numbers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
'''You are given two non-empty linked lists representing two non-negative integers.
2+
The digits are stored in reverse order, and each of their nodes contains a single digit.
3+
Add the two numbers and return the sum as a linked list.
4+
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
5+
6+
Constraints:
7+
-The number of nodes in each linked list is in the range [1, 100].
8+
-The0 <= Node.val <= 9
9+
-It is guaranteed that the list represents a number that does not have leading zeros.
10+
'''
11+
12+
113
class Solution:
214
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
315
dope = ListNode(0)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'''question Given a string s, find the length of the longest substring
2+
without repeating characters.
3+
Constraints:
4+
0 <= s.length <= 5 * 104
5+
s consists of English letters, digits, symbols and spaces.
6+
'''
7+
class Solution:
8+
def lengthOfLongestSubstring(self, s: str) -> int:
9+
v =0 #map to store information v and k
10+
k = 0
11+
m ={}
12+
result = 0
13+
while k < len(s):
14+
if s[k] not in m or v>m[s[k]]:
15+
result = max(result,(k-v+1))
16+
m[s[k]] = k
17+
else:
18+
v = m[s[k]]+1
19+
result = max(result,(k-v+1))
20+
k-=1
21+
k+=1
22+
return result
23+
24+
#used sliding window to solve this problem

twosum.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
'''Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
2+
3+
You may assume that each input would have exactly one solution, and you may not use the same element twice.
4+
5+
You can return the answer in any order.
6+
Constraints:
7+
2 <= nums.length <= 105
8+
-109 <= nums[i] <= 109
9+
-109 <= target <= 109
10+
Only one valid answer exists.
11+
'''
12+
13+
114
class Solution:
215
def twoSum(self, nums: List[int], target: int) -> List[int]:
316
dict = {}

0 commit comments

Comments
 (0)