-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #987 from 0xff-dev/1947
Add solution and test-cases for problem 1947
- Loading branch information
Showing
3 changed files
with
65 additions
and
27 deletions.
There are no files selected for viewing
37 changes: 23 additions & 14 deletions
37
leetcode/1901-2000/1947.Maximum-Compatibility-Score-Sum/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 32 additions & 2 deletions
34
leetcode/1901-2000/1947.Maximum-Compatibility-Score-Sum/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,35 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(students [][]int, mentors [][]int) int { | ||
var ( | ||
dfs func(int, []bool) int | ||
match func(int, int) int | ||
) | ||
match = func(i, j int) int { | ||
ans := 0 | ||
for k := range students[i] { | ||
if mentors[j][k] == students[i][k] { | ||
ans++ | ||
} | ||
} | ||
return ans | ||
} | ||
|
||
dfs = func(index int, used []bool) int { | ||
cur := 0 | ||
if index == len(students) { | ||
return cur | ||
} | ||
|
||
for i := range mentors { | ||
if used[i] { | ||
continue | ||
} | ||
used[i] = true | ||
cur = max(cur, match(index, i)+dfs(index+1, used)) | ||
used[i] = false | ||
} | ||
return cur | ||
} | ||
return dfs(0, make([]bool, len(students))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters