Skip to content

Commit 4d04c28

Browse files
authored
Merge pull request #175 from Hinsteny/master
Add Solution.py for 0003 and 0421
2 parents 0a79699 + c51b492 commit 4d04c28

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def lengthOfLongestSubstring(self, s: str):
3+
max = 0
4+
length = len(s)
5+
substr = ""
6+
for i in range(0, length):
7+
index = substr.find(s[i])
8+
if index > -1:
9+
substr = substr[index + 1:]
10+
substr += s[i]
11+
max = (max if (max > len(substr)) else len(substr))
12+
return max
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def findMaximumXOR(self, nums: List[int]) -> int:
3+
max = 0
4+
mask = 0
5+
for i in range(30, -1, -1):
6+
current = 1 << i
7+
# 期望的二进制前缀
8+
mask = mask ^ current
9+
# 在当前前缀下, 数组内的前缀位数所有情况集合
10+
_set = set()
11+
for num in nums:
12+
_set.add(num & mask)
13+
# 期望最终异或值的从右数第i位为1, 再根据异或运算的特性推算假设是否成立
14+
flag = max | current
15+
for prefix in _set:
16+
if prefix ^ flag in _set:
17+
max = flag
18+
break
19+
return max

solution/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
│   ├── README.md
2626
│   ├── Solution.go
2727
│   ├── Solution.java
28-
│   └── Solution.js
28+
│   ├── Solution.js
29+
│   └── Solution.py
2930
├── 0004.Median of Two Sorted Arrays
3031
│   ├── README.md
3132
│   ├── Solution.cpp
@@ -767,7 +768,8 @@
767768
│   └── Solution.java
768769
├── 0421.Maximum XOR of Two Numbers in an Array
769770
│   ├── README.md
770-
│   └── Solution.java
771+
│   ├── Solution.java
772+
│   └── Solution.py
771773
├── 0423.Reconstruct Original Digits from English
772774
│   └── Solution.cpp
773775
├── 0427.Construct Quad Tree

0 commit comments

Comments
 (0)