Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 44a211b

Browse files
Update 592._Fraction_Addition_and_Subtraction.md
1 parent 17339e9 commit 44a211b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎docs/Leetcode_Solutions/592._Fraction_Addition_and_Subtraction.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,19 @@ class Solution(object):
101101
return res
102102
```
103103

104+
> 思路 2
105+
******- 时间复杂度: O(N)******- 空间复杂度: O(N)******
106+
107+
108+
我怕不是个智障吧,还小自豪,。。。。看了discuss里面[lee215](https://leetcode.com/problems/fraction-addition-and-subtraction/discuss/103387/Python-easy-understood-2-line-solution)大神的答案,我tm。。。。
109+
```python
110+
class Solution(object):
111+
def fractionAddition(self, expression):
112+
"""
113+
:type expression: str
114+
:rtype: str
115+
"""
116+
from fractions import Fraction
117+
res = sum(map(Fraction, expression.replace('+', ' +').replace('-', ' -').split()))
118+
return str(res.numerator) + '/' + str(res.denominator)
119+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /