Skip to content

Commit dbf82cb

Browse files
add 13 go
1 parent ea92fb8 commit dbf82cb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LeetCode
1616
|0010|[Regular Expression Matching](https://leetcode.com/problems/regular-expression-matching) | c | [c++](./src/0010-Regular-Expression-Matching/0010.cpp) |[python](./src/0010-Regular-Expression-Matching/0010.py)|[go](./src/0010-Regular-Expression-Matching/0010.go)||Hard|
1717
|0011|[Container With Most Water](https://leetcode.com/problems/queue-reconstruction-by-height/) | c | [c++](./src/0011-Container-With-Most-Water/0011.cpp)|[python](./src/0011-container-with-most-water/0011.py)|[go](./src/0011-container-with-most-water/0011.go)||Medium|
1818
|0012|[Integer to Roman](https://leetcode.com/problems/integer-to-roman) | c | [c++](./src/0012-Integer-to-Roman/0012.cpp) |[python](./src/0012-Integer-to-Roman/0012.py)|[go](./src/0012-Integer-to-Roman/0012.go)||Medium|
19-
|0013|[Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | c | [c++](./src/0013-Roman-to-Integer/0013.cpp) |[python](./src/0013-Roman-to-Integer/0013.py)|||Easy|
19+
|0013|[Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | c | [c++](./src/0013-Roman-to-Integer/0013.cpp) |[python](./src/0013-Roman-to-Integer/0013.py)|[go](./src/0013-Roman-to-Integer/0013.go)||Easy|
2020
|0014|[Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | c | [c++](./src/0014-Longest-Common-Prefix/0014.cpp) |[python](./src/0014-Longest-Common-Prefix/0014.py)|||Easy|
2121
|0015|[3Sum](https://leetcode.com/problems/3sum/) | c | [c++](./src/0015-3Sum/0015.cpp) |[python](./src/0015-3Sum/0015.py)|||Medium|
2222
|0016|[3Sum Closest](https://leetcode.com/problems/3Sum-Closest/) | c | [c++](./src/0016-3Sum-Closest/0016.cpp) |[python](./src/0016-3Sum-Closest/0016.py)|||Medium|

src/0013-Roman-to-Integer/0013.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func romanToInt(s string) int {
2+
s_dict := map[byte]int{'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
3+
res, pre := 0, 0
4+
for _, ch := range []byte(s) {
5+
cur := s_dict[ch]
6+
if pre < cur {
7+
res += cur - 2 * pre
8+
} else {
9+
res += cur
10+
}
11+
pre = cur
12+
}
13+
return res
14+
}

0 commit comments

Comments
 (0)