8000 update at 2018-05-02 · bonfy/leetcode@42e3eaf · GitHub
[go: up one dir, main page]

Skip to content

Commit 42e3eaf

Browse files
committed
update at 2018-05-02
1 parent 73eff1e commit 42e3eaf

File tree

7 files changed

+116
-25
lines changed

7 files changed

+116
-25
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
# If no valid conversion could be performed, a zero value is returned.
1313
#
1414
# Note:
15-
# Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (231 − 1) or INT_MIN (−231) is returned.
15+
#
16+
#
17+
# Only the space character ' ' is considered as whitespace character.
18+
# Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (231 − 1) or INT_MIN (−231) is returned.
19+
#
1620
#
1721
# Example 1:
1822
#

134-gas-station/gas-station.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,56 @@
11
# -*- coding:utf-8 -*-
22

33

4-
#
54
# There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
65
#
6+
# You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
77
#
8+
# Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
89
#
9-
# You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
10+
# Note:
1011
#
1112
#
13+
# If there exists a solution, it is guaranteed to be unique.
14+
# Both input arrays are non-empty and have the same length.
15+
# Each element in the input arrays is a non-negative integer.
1216
#
13-
# Return the starting gas station's index if you can travel around the circuit once, otherwise return -1.
1417
#
18+
# Example 1:
1519
#
1620
#
17-
# Note:
18-
# The solution is guaranteed to be unique.
21+
# Input:
22+
# gas = [1,2,3,4,5]
23+
# cost = [3,4,5,1,2]
24+
#
25+
# Output: 3
26+
#
27+
# Explanation:
28+
# Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
29+
# Travel to station 4. Your tank = 4 - 1 + 5 = 8
30+
# Travel to station 0. Your tank = 8 - 2 + 1 = 7
31+
# Travel to station 1. Your tank = 7 - 3 + 2 = 6
32+
# Travel to station 2. Your tank = 6 - 4 + 3 = 5
33+
# Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
34+
# Therefore, return 3 as the starting index.
35+
#
36+
#
37+
# Example 2:
38+
#
39+
#
40+
# Input:
41+
# gas = [2,3,4]
42+
# cost = [3,4,3]
43+
#
44+
# Output: -1
45+
#
46+
# Explanation:
47+
# You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
48+
# Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
49+
# Travel to station 0. Your tank = 4 - 3 + 2 = 3
50+
# Travel to station 1. Your tank = 3 - 3 + 3 = 3
51+
# You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
52+
# Therefore, you can't travel around the circuit once no matter where you start.
53+
#
1954
#
2055

2156

136-single-number/single-number.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# Given an array of integers, every element appears twice except for one. Find that single one.
5-
#
4+
# Given a non-empty array of integers, every element appears twice except for one. Find that single one.
65
#
76
# Note:
7+
#
88
# Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
99
#
10+
# Example 1:
11+
#
12+
#
13+
# Input: [2,2,1]
14+
# Output: 1
15+
#
16+
#
17+
# Example 2:
18+
#
19+
#
20+
# Input: [4,1,2,1,2]
21+
# Output: 4
22+
#
23+
#
1024

1125

1226
class Solution(object):

137-single-number-ii/single-number-ii.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
# -*- coding:utf-8 -*-
22

33

4+
# Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
45
#
5-
# Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
6+
# Note:
67
#
8+
# Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
79
#
10+
# Example 1:
811
#
9-
# Note:
10-
# Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
12+
#
13+
# Input: [2,2,3,2]
14+
# Output: 3
15+
#
16+
#
17+
# Example 2:
18+
#
19+
#
20+
# Input: [0,1,0,1,0,1,99]
21+
# Output: 99
1122
#
1223

1324

189-rotate-array/rotate-array.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
# -*- coding:utf-8 -*-
22

33

4-
# Rotate an array of n elements to the right by k steps.
4+
# Given an array, rotate the array to the right by k steps, where k is non-negative.
55
#
6-
# For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].
6+
# Example 1:
77
#
8-
# Note:
9-
# Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.
108
#
11-
# [show hint]
9+
# Input: [1,2,3,4,5,6,7] and k = 3
10+
# Output: [5,6,7,1,2,3,4]
11+
# Explanation:
12+
# rotate 1 steps to the right: [7,1,2,3,4,5,6]
13+
# rotate 2 steps to the right: [6,7,1,2,3,4,5]
14+
# rotate 3 steps to the right: [5,6,7,1,2,3,4]
15+
#
16+
#
17+
# Example 2:
18+
#
19+
#
20+
# Input: [-1,-100,3,99] and k = 2
21+
# Output: [3,99,-1,-100]
22+
# Explanation:
23+
# rotate 1 steps to the right: [99,-1,-100,3]
24+
# rotate 2 steps to the right: [3,99,-1,-100]
25+
#
26+
#
27+
# Note:
1228
#
13-
# Hint:
14-
# Could you do it in-place with O(1) extra space?
1529
#
16-
# Related problem: Reverse Words in a String II
30+
# Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.
31+
# Could you do it in-place with O(1) extra space?
1732
#
18-
# Credits:
19-
# Special thanks to @Freezen for adding this problem and creating all test cases.
2033
#
2134

2235

206-reverse-linked-list/reverse-linked-list.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33

44
# Reverse a singly linked list.
55
#
6-
# click to show more hints.
6+
# Example:
7+
#
8+
#
9+
# Input: 1->2->3->4->5->NULL
10+
# Output: 5->4->3->2->1->NULL
11+
#
12+
#
13+
# Follow up:
714
#
8-
# Hint:
915
# A linked list can be reversed either iteratively or recursively. Could you implement both?
1016
#
1117

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# :pencil2: Leetcode Solutions with Python,Javascript
2-
Update time: 2018-04-20 17:17:06
2+
Update time: 2018-05-02 09:30:43
33

44
Auto created by [leetcode_generate](https://github.com/bonfy/leetcode)
55

6-
I have solved **97 / 734** problems
6+
I have solved **97 / 742** problems
77
while there are **133** problems still locked.
88

99
If you want to use this tool please follow this [Usage Guide](https://github.com/bonfy/leetcode/blob/master/README_leetcode_generate.md)
@@ -750,3 +750,11 @@ If you are loving solving problems in leetcode, please contact me to enjoy it to
750750
|835|[linked-list-components](https://leetcode.com/problems/linked-list-components)||[:memo:](https://leetcode.com/articles/linked-list-components/)|Medium|
751751
|836|[race-car](https://leetcode.com/problems/race-car)||[:memo:](https://leetcode.com/articles/race-car/)|Hard|
752752
|837|[most-common-word](https://leetcode.com/problems/most-common-word)||[:memo:](https://leetcode.com/articles/most-common-word/)|Easy|
753+
|839|[short-encoding-of-words](https://leetcode.com/problems/short-encoding-of-words)||[:memo:](https://leetcode.com/articles/short-encoding-of-words/)|Medium|
754+
|841|[shortest-distance-to-a-character](https://leetcode.com/problems/shortest-distance-to-a-character)||[:memo:](https://leetcode.com/articles/shortest-distance-to-a-character/)|Easy|
755+
|842|[card-flipping-game](https://leetcode.com/problems/card-flipping-game)||[:memo:](https://leetcode.com/articles/card-flipping-game/)|Medium|
756+
|843|[binary-trees-with-factors](https://leetcode.com/problems/binary-trees-with-factors)||[:memo:](https://leetcode.com/articles/binary-trees-with-factors/)|Medium|
757+
|851|[goat-latin](https://leetcode.com/problems/goat-latin)||[:memo:](https://leetcode.com/articles/goat-latin/)|Easy|
758+
|852|[friends-of-appropriate-ages](https://leetcode.com/problems/friends-of-appropriate-ages)||[:memo:](https://leetcode.com/articles/friends-of-appropriate-ages/)|Medium|
759+
|853|[most-profit-assigning-work](https://leetcode.com/problems/most-profit-assigning-work)||[:memo:](https://leetcode.com/articles/most-profit-assigning-work/)|Medium|
760+
|854|[making-a-large-island](https://leetcode.com/problems/making-a-large-island)||[:memo:](https://leetcode.com/articles/making-a-large-island/)|Hard|

0 commit comments

Comments
 (0)
0