We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 60a1af2 commit 49f9a47Copy full SHA for 49f9a47
solution/0763.Partition Labels/Solution.go
@@ -0,0 +1,30 @@
1
+/**
2
+ * @lc app=leetcode.cn id=763 lang=golang
3
+ * Accepted
4
+ * 116/116 cases passed (0 ms)
5
+ * Your runtime beats 100 % of golang submissions
6
+ * Your memory usage beats 66.67 % of golang submissions (2.3 MB)
7
+ * time O(n) space O(k)
8
+ */
9
+
10
+func partitionLabels(S string) []int {
11
+ flag := 0
12
+ tmp := 0
13
+ start := -1
14
+ last := [26]int{}
15
+ ret := []int{}
16
+ for i := 0; i < len(S); i++ {
17
+ last[S[i]-'a'] = i
18
+ }
19
20
+ tmp = last[S[i]-'a']
21
+ if flag < tmp {
22
+ flag = tmp
23
24
+ if flag == i {
25
+ ret = append(ret, flag-start)
26
+ start = flag
27
28
29
+ return ret
30
+}
0 commit comments