Skip to content

Commit 7ca9bc3

Browse files
committed
update at 2019-02-18
1 parent 00e2299 commit 7ca9bc3

File tree

5 files changed

+131
-51
lines changed

5 files changed

+131
-51
lines changed

024-swap-nodes-in-pairs/swap-nodes-in-pairs.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33

44
# Given a linked list, swap every two adjacent nodes and return its head.
55
#
6-
# Example:
7-
#
6+
# You may not modify the values in the list's nodes, only nodes itself may be changed.
87
#
9-
# Given 1->2->3->4, you should return the list as 2->1->4->3.
8+
#  
109
#
11-
# Note:
10+
# Example:
1211
#
1312
#
14-
# Your algorithm should use only constant extra space.
15-
# You may not modify the values in the list's nodes, only nodes itself may be changed.
13+
# Given 1->2->3->4, you should return the list as 2->1->4->3.
1614
#
1715
#
1816

071-simplify-path/simplify-path.py

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

33

4-
# Given an absolute path for a file (Unix-style), simplify it. 
4+
# Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.
55
#
6-
# For example,
7-
# path = "/home/", => "/home"
8-
# path = "/a/./b/../../c/", => "/c"
9-
# path = "/a/../../b/../c//.//", => "/c"
10-
# path = "/a//b////c/d//././/..", => "/a/b/c"
6+
# In a UNIX-style file system, a period . refers to the current directory. Furthermore, a double period .. moves the directory up a level. For more information, see: Absolute path vs relative path in Linux/Unix
117
#
12-
# In a UNIX-style file system, a period ('.') refers to the current directory, so it can be ignored in a simplified path. Additionally, a double period ("..") moves up a directory, so it cancels out whatever the last directory was. For more information, look here: https://en.wikipedia.org/wiki/Path_(computing)#Unix_style
8+
# Note that the returned canonical path must always begin with a slash /, and there must be only a single slash / between two directory names. The last directory name (if it exists) must not end with a trailing /. Also, the canonical path must be the shortest string representing the absolute path.
139
#
14-
# Corner Cases:
10+
#  
1511
#
12+
# Example 1:
1613
#
17-
# Did you consider the case where path = "/../"?
18-
# In this case, you should return "/".
19-
# Another corner case is the path might contain multiple slashes '/' together, such as "/home//foo/".
20-
# In this case, you should ignore redundant slashes and return "/home/foo".
14+
#
15+
# Input: "/home/"
16+
# Output: "/home"
17+
# Explanation: Note that there is no trailing slash after the last directory name.
18+
#
19+
#
20+
# Example 2:
21+
#
22+
#
23+
# Input: "/../"
24+
# Output: "/"
25+
# Explanation: Going one level up from the root directory is a no-op, as the root level is the highest level you can go.
26+
#
27+
#
28+
# Example 3:
29+
#
30+
#
31+
# Input: "/home//foo/"
32+
# Output: "/home/foo"
33+
# Explanation: In the canonical path, multiple consecutive slashes are replaced by a single one.
34+
#
35+
#
36+
# Example 4:
37+
#
38+
#
39+
# Input: "/a/./b/../../c/"
40+
# Output: "/c"
41+
#
42+
#
43+
# Example 5:
44+
#
45+
#
46+
# Input: "/a/../../b/../c//.//"
47+
# Output: "/c"
48+
#
49+
#
50+
# Example 6:
51+
#
52+
#
53+
# Input: "/a//b////c/d//././/.."
54+
# Output: "/a/b/c"
2155
#
2256
#
2357

237-delete-node-in-a-linked-list/delete-node-in-a-linked-list.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@
66
# Given linked list -- head = [4,5,1,9], which looks like following:
77
#
88
#
9-
# 4 -> 5 -> 1 -> 9
109
#
10+
#  
1111
#
1212
# Example 1:
1313
#
1414
#
1515
# Input: head = [4,5,1,9], node = 5
1616
# Output: [4,1,9]
17-
# Explanation: You are given the second node with value 5, the linked list
18-
#   should become 4 -> 1 -> 9 after calling your function.
17+
# Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.
1918
#
2019
#
2120
# Example 2:
2221
#
2322
#
2423
# Input: head = [4,5,1,9], node = 1
2524
# Output: [4,5,9]
26-
# Explanation: You are given the third node with value 1, the linked list
27-
# should become 4 -> 5 -> 9 after calling your function.
25+
# Explanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.
2826
#
2927
#
28+
#  
29+
#
3030
# Note:
3131
#
3232
#

526-beautiful-arrangement/beautiful-arrangement.py

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

33

4-
#
54
# Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 <= i <= N) in this array:
65
#
7-
# The number at the ith position is divisible by i.
8-
# i is divisible by the number at the ith position.
96
#
7+
# The number at the ith position is divisible by i.
8+
# i is divisible by the number at the ith position.
109
#
1110
#
11+
#  
1212
#
1313
# Now given N, how many beautiful arrangements can you construct?
1414
#
15-
#
1615
# Example 1:
1716
#
17+
#
1818
# Input: 2
1919
# Output: 2
2020
# Explanation:
21+
#
2122
# The first beautiful arrangement is [1, 2]:
23+
#
2224
# Number at the 1st position (i=1) is 1, and 1 is divisible by i (i=1).
25+
#
2326
# Number at the 2nd position (i=2) is 2, and 2 is divisible by i (i=2).
27+
#
2428
# The second beautiful arrangement is [2, 1]:
29+
#
2530
# Number at the 1st position (i=1) is 2, and 2 is divisible by i (i=1).
31+
#
2632
# Number at the 2nd position (i=2) is 1, and i (i=2) is divisible by 1.
2733
#
2834
#
35+
#  
2936
#
3037
# Note:
3138
#
32-
# N is a positive integer and will not exceed 15.
3339
#
40+
# N is a positive integer and will not exceed 15.
41+
#
42+
#
43+
#  
3444
#
3545

3646

0 commit comments

Comments
 (0)