-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_new_problem.sh
More file actions
executable file
·84 lines (64 loc) · 1.4 KB
/
setup_new_problem.sh
File metadata and controls
executable file
·84 lines (64 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash -e
usage="Usage: $(basename "$0") [-h] [-n <integer>] [-t <string>]
Script to initialize a leetcode problem in this project.
Options:
-n the leetcode problem id
-t the leetcode problem title
"
LEETCODE_ID=""
LEETCODE_TITLE=""
while getopts :hn:t: OPTION; do
case $OPTION in
h) echo "$usage"
exit
;;
n) LEETCODE_ID=$OPTARG
;;
t) LEETCODE_TITLE=$OPTARG
;;
:) printf "missing argument for -%s\\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?) printf "illegal option: -%s\\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
if [[ ! "$LEETCODE_ID" =~ ^[0-9]+$ ]]; then
echo "valid Leetcode ID required"
exit 1
fi
if [ -z "$LEETCODE_TITLE" ]; then
echo "valid leetcode title required"
exit 1
fi
work_dir=${LEETCODE_ID}_$(echo $LEETCODE_TITLE | sed -E 's/[\ .-]/_/g')
mkdir -p $work_dir
cat > $work_dir/${LEETCODE_ID}.md << EOF
# Question:
**Note**:
**Example**:
\`\`\`
here goes the example
\`\`\`
# Analysis
# Tips
# Code
\`\`\`go
here goes the code
\`\`\`
EOF
cat > $work_dir/main.go << EOF
package main
import (
"fmt"
)
func main() {
fmt.Println("hello world!")
}
EOF
cat >> README.md << EOF
* [${LEETCODE_ID}. $(echo ${LEETCODE_TITLE} | sed 's/[-_.]/ /g; s/\<./\U&/g')]($work_dir/${LEETCODE_ID}.md)
EOF