Skip to content

Commit 1e5615a

Browse files
committed
commit changes to gh-pages aug 18
1 parent 8328776 commit 1e5615a

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

_includes/_root/gas-station/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
## Guessing
12

2-
## TODO
3-
* write down thinking
3+
This problem is to find a UNIQUE station `i`, such that
44

5+
* SUM(gas[0 .. i-1]) - SUM(cost[0 .. i-1]) + SUM(gas[i .. end]) - SUM(cost[i .. end]) >= 0
6+
* SUM(gas[0 .. i-1]) - SUM(cost[0 .. i-1]) < 0
7+
8+
`SUM(gas[0 .. i-1]) - SUM(cost[0 .. i-1]) < 0` is to guarantee that the `i` is unique.
9+
10+
If `SUM(gas[0 .. i-1]) - SUM(cost[0 .. i-1]) < 0` and `SUM(gas[0 .. i-1]) - SUM(cost[0 .. i-1]) + SUM(gas[i .. end]) - SUM(cost[i .. end]) >= 0`, that is, `0 .. i-1` are all valid stations.
11+
12+
## Brute force
13+
14+
Just search through from `0` to `end`, find the valid `i`.
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
## Definition
2+
3+
4+
```
5+
6+
permute(num) = empty num is empty
7+
num num has only one element
8+
n + permute(num - n) [n in num] otherwise
9+
10+
```
11+
112

2-
## TODO
3-
* write down thinking
413

gas-station/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
layout: solution
33
title: Gas Station
4-
date: 2014-07-23 02:42:48 +0800
4+
date: 2014-08-17 23:57:14 +0800
5+
eaten: true
56
---
67
{% assign leetcode_name = {{page.path | remove: '/index.md'}} %}
78
{% assign leetcode_readme = {{leetcode_name | append: '/README.md' | prepend: '_root/' }} %}

permutations/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
layout: solution
33
title: Permutations
4-
date: 2014-07-31 12:08:12 +0800
4+
date: 2014-08-17 23:07:06 +0800
5+
eaten: true
56
---
67
{% assign leetcode_name = {{page.path | remove: '/index.md'}} %}
78
{% assign leetcode_readme = {{leetcode_name | append: '/README.md' | prepend: '_root/' }} %}

0 commit comments

Comments
 (0)