Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 03c0fa2

Browse files
author
Shuo
authored
Merge pull request #248 from openset/develop
Add: Delete Columns to Make Sorted
2 parents a394b1e + 49eeabe commit 03c0fa2

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
11
package delete_columns_to_make_sorted
2+
3+
func minDeletionSize(A []string) int {
4+
ans := 0
5+
for i := 0; i < len(A[0]); i++ {
6+
for j, str := range A[1:] {
7+
if str[i] < A[j][i] {
8+
ans++
9+
break
10+
}
11+
}
12+
}
13+
return ans
14+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
11
package delete_columns_to_make_sorted
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input []string
7+
expected int
8+
}
9+
10+
func TestMinDeletionSize(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: []string{"cba", "daf", "ghi"},
14+
expected: 1,
15+
},
16+
{
17+
input: []string{"a", "b"},
18+
expected: 0,
19+
},
20+
{
21+
input: []string{"zyx", "wvu", "tsr"},
22+
expected: 3,
23+
},
24+
}
25+
for _, tc := range tests {
26+
output := minDeletionSize(tc.input)
27+
if output != tc.expected {
28+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
29+
}
30+
}
31+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /