Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Add Solution.py for 0003 and 0421 #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def lengthOfLongestSubstring(self, s: str):
max = 0
length = len(s)
substr = ""
for i in range(0, length):
index = substr.find(s[i])
if index > -1:
substr = substr[index + 1:]
substr += s[i]
max = (max if (max > len(substr)) else len(substr))
return max
19 changes: 19 additions & 0 deletions solution/0421.Maximum XOR of Two Numbers in an Array/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def findMaximumXOR(self, nums: List[int]) -> int:
max = 0
mask = 0
for i in range(30, -1, -1):
current = 1 << i
# 期望的二进制前缀
mask = mask ^ current
# 在当前前缀下, 数组内的前缀位数所有情况集合
_set = set()
for num in nums:
_set.add(num & mask)
# 期望最终异或值的从右数第i位为1, 再根据异或运算的特性推算假设是否成立
flag = max | current
for prefix in _set:
if prefix ^ flag in _set:
max = flag
break
return max
6 changes: 4 additions & 2 deletions solution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
│   ├── README.md
│   ├── Solution.go
│   ├── Solution.java
│   └── Solution.js
│   ├── Solution.js
│   └── Solution.py
├── 0004.Median of Two Sorted Arrays
│   ├── README.md
│   ├── Solution.cpp
Expand Down Expand Up @@ -767,7 +768,8 @@
│   └── Solution.java
├── 0421.Maximum XOR of Two Numbers in an Array
│   ├── README.md
│   └── Solution.java
│   ├── Solution.java
│   └── Solution.py
├── 0423.Reconstruct Original Digits from English
│   └── Solution.cpp
├── 0427.Construct Quad Tree
Expand Down