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

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 8 Week_02/id_103/.idea/id_103.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 6 Week_02/id_103/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 8 Week_02/id_103/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 6 Week_02/id_103/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

221 changes: 221 additions & 0 deletions 221 Week_02/id_103/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions 48 Week_02/id_103/HashTable/LeetCode_242_103.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package HashTable

//已通过
func IsAnagram(s string, t string) bool {
if len(s) != len(t){
return false
}
sb :=[]byte(s)
collectionMap := map[byte]int{}
for i := 0; i< len(sb);i++ {
value,ok := collectionMap[sb[i]]
if !ok {
collectionMap[sb[i]] = 1
}else{
collectionMap[sb[i]] = value + 1
}
}

st := []byte(t)
for i := 0; i< len(st);i++ {
value,ok := collectionMap[st[i]]
if !ok {
return false
}else{
if value == 0{
return false
}
collectionMap[st[i]] = value - 1
}
}
return true
}

func IsAnagram2(s string, t string) bool {
tmpA,tmpB :=make([]int,26),make([]int,26)
for i:=0;i<len(s);i++ {
tmpA[s[i]-'a']++
}
for i:=0;i<len(t);i++ {
tmpB[t[i]-'a']++
}
for i:=0;i<26;i++ {
if tmpA[i] != tmpB[i] {
return false
}
}
return true
}
41 changes: 41 additions & 0 deletions 41 Week_02/id_103/HashTable/LeetCode_671_103.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package HashTable

import "math"
//Finished
var res = -1
func findSecondMinimumValue(root *TreeNode) int {
min := minValue(root)
res = math.MaxInt64
helpFind(root,min)
if res == math.MaxInt64{
return -1
}
return res
}

func helpFind(root *TreeNode, min int) {
if root != nil{
if root.Val > min && root.Val < res{
res = root.Val
}
helpFind(root.Left,min)
helpFind(root.Right,min)
}
}

func minValue(root *TreeNode) int {
if root.Left == nil && root.Right == nil{
return root.Val
}
if root.Left == nil{
return minValue(root.Right)
}
if root.Right == nil{
return minValue(root.Left)
}
if root.Left.Val < root.Right.Val{
return minValue(root.Left)
}else {
return minValue(root.Right)
}
}
40 changes: 40 additions & 0 deletions 40 Week_02/id_103/HashTable/LeetCode_692_103.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package HashTable

import (
"sort"
)
//测试没过,因为顺序问题
func TopKFrequent(words []string, k int) []string {
collectionMap := map[string]int{}

for _, v := range words {
if intV,ok:=collectionMap[v];ok{
collectionMap[v] = intV +1
}else{
collectionMap[v] = 1
}
}
res := []string{}
counts := make([]int,0)
for _, v := range collectionMap {
counts = append(counts, v)
}
sort.Ints(counts)
searchResult := counts[len(counts)-k:]

for k,v := range collectionMap {
if help(searchResult,v){
res = append(res, k)
}
}
return res
}

func help (arr []int,compare int) bool{
for e := range arr {
if compare == arr[e]{
return true
}
}
return false;
}
7 changes: 7 additions & 0 deletions 7 Week_02/id_103/HashTable/TreeNode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package HashTable

type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.