Skip to content

Commit 9f5afbb

Browse files
committed
update at 2017-09-04
1 parent ceb3ffd commit 9f5afbb

File tree

90 files changed

+466
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+466
-54
lines changed

001-two-sum/two-sum.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// Because nums[0] + nums[1] = 2 + 7 = 9,
1111
// return [0, 1].
1212
//
13+
//
1314

1415

1516
/**

001-two-sum/two-sum.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# Because nums[0] + nums[1] = 2 + 7 = 9,
1414
# return [0, 1].
1515
#
16+
#
1617

1718

1819
class Solution(object):
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# -*- coding:utf-8 -*-
2+
3+
4+
# 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 contain a single digit. Add the two numbers and return it as a linked list.
5+
#
6+
# You may assume the two numbers do not contain any leading zero, except the number 0 itself.
7+
#
8+
#
9+
# Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
10+
# Output: 7 -> 0 -> 8
11+
12+
13+
# Definition for singly-linked list.
14+
15+
# class ListNode(object):
16+
# def __init__(self, x):
17+
# self.val = x
18+
# self.next = None
19+
20+
class Solution(object):
21+
def addTwoNumbers(self, l1, l2):
22+
"""
23+
:type l1: ListNode
24+
:type l2: ListNode
25+
:rtype: ListNode
26+
"""
27+
if(l1 is None and l2 is None):
28+
return None
29+
30+
head = ListNode(0)
31+
point = head
32+
carry = 0
33+
while l1 is not None and l2 is not None:
34+
s = carry + l1.val + l2.val
35+
point.next = ListNode(s % 10)
36+
carry = s / 10
37+
l1 = l1.next
38+
l2 = l2.next
39+
point = point.next
40+
41+
while l1 is not None:
42+
s = carry + l1.val
43+
point.next = ListNode(s % 10)
44+
carry = s / 10
45+
l1 = l1.next
46+
point = point.next
47+
48+
while l2 is not None:
49+
s = carry + l2.val
50+
point.next = ListNode(s % 10)
51+
carry = s / 10
52+
l2 = l2.next
53+
point = point.next
54+
55+
if carry != 0:
56+
point.next = ListNode(carry)
57+
58+
return head.next
59+
60+
61+
62+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding:utf-8 -*-
2+
3+
4+
# Given a string, find the length of the longest substring without repeating characters.
5+
#
6+
# Examples:
7+
#
8+
# Given "abcabcbb", the answer is "abc", which the length is 3.
9+
#
10+
# Given "bbbbb", the answer is "b", with the length of 1.
11+
#
12+
# Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
13+
14+
15+
class Solution(object):
16+
def lengthOfLongestSubstring(self, s):
17+
"""
18+
:type s: str
19+
:rtype: int
20+
"""
21+
22+
longest, start, visited = 0, 0, [False for _ in range(256)]
23+
for ind, val in enumerate(s):
24+
if not visited[ord(val)]:
25+
visited[ord(val)] = True
26+
else:
27+
while val != s[start]:
28+
visited[ord(s[start])] = False
29+
start += 1
30+
start += 1
31+
longest = max(longest, ind - start + 1)
32+
return longest
33+

004-median-of-two-sorted-arrays/median-of-two-sorted-arrays.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#
2222
# The median is (2 + 3)/2 = 2.5
2323
#
24+
#
2425

2526

2627
class Solution(object):

005-longest-palindromic-substring/longest-palindromic-substring.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#
2020
# Output: "bb"
2121
#
22+
#
2223

2324

2425
class Solution(object):

006-zigzag-conversion/zigzag-conversion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#
1717
# string convert(string text, int nRows);
1818
#
19-
# convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR".
19+
# convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR".
20+
#
2021

2122

2223
class Solution(object):

007-reverse-integer/reverse-integer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
#
2626
#
2727
# Note:
28-
# The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.
28+
# The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.
29+
#
2930

3031

3132
class Solution(object):

008-string-to-integer-atoi/string-to-integer-atoi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#
2727
# If no valid conversion could be performed, a zero value is returned. If the correct value is out of the range of representable values, INT_MAX (2147483647) or INT_MIN (-2147483648) is returned.
2828
#
29+
#
2930

3031

3132
class Solution(object):

009-palindrome-number/palindrome-number.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
# There is a more generic way of solving this problem.
1717
#
18+
#
1819

1920

2021
class Solution(object):

0 commit comments

Comments
 (0)