-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.patch
130 lines (121 loc) · 3.19 KB
/
diff.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
diff --git a/ll_cycle/main.go b/ll_cycle/main.go
index e1d6645..73cb4e1 100644
--- a/ll_cycle/main.go
+++ b/ll_cycle/main.go
@@ -10,8 +10,8 @@ type Node struct {
Value int
}
-// CheckCycle -
-func CheckCycle(head *Node) bool {
+// CheckCycleCustom -
+func CheckCycleCustom(head *Node) bool {
if head == nil || head.Next == nil {
return false //
}
@@ -32,6 +32,31 @@ func CheckCycle(head *Node) bool {
return false
}
+// CheckCycleSimplified
+func CheckCycleSimplified(head *Node) bool {
+ // Handle empty or single-node lists directly:
+ if head == nil || head.Next == nil {
+ return false
+ }
+
+ // Use descriptive variable names:
+ slowPointer := head
+ fastPointer := head.Next
+
+ // Loop until fastPointer reaches the end or a cycle is detected:
+ for fastPointer != nil && fastPointer.Next != nil {
+ if fastPointer == slowPointer {
+ return true // Cycle detected
+ }
+
+ // Move pointers at different speeds:
+ slowPointer = slowPointer.Next
+ fastPointer = fastPointer.Next.Next
+ }
+
+ return false // No cycle found
+}
+
// InsertNode -
func InsertNode(node, head *Node) *Node {
node.Next = head
@@ -57,7 +82,7 @@ func main() {
// Test 1 head = nil
head = nil
- if CheckCycle(head) == true {
+ if CheckCycleSimplified(head) == true {
fmt.Println("has Cycle")
} else {
fmt.Println("No Cycle")
@@ -71,7 +96,7 @@ func main() {
}
// Test 2.1 No Cycle
- if CheckCycle(head) == true {
+ if CheckCycleSimplified(head) == true {
fmt.Println("has Cycle")
} else {
fmt.Println("No Cycle")
@@ -79,7 +104,7 @@ func main() {
// Test 2.2 Cycle
CreateCycle(head)
- if CheckCycle(head) == true {
+ if CheckCycleSimplified(head) == true {
fmt.Println("has Cycle")
} else {
fmt.Println("No Cycle")
@@ -93,7 +118,7 @@ func main() {
}
// Test 3.1
- if CheckCycle(head) == true {
+ if CheckCycleSimplified(head) == true {
fmt.Println("has Cycle")
} else {
fmt.Println("No Cycle")
@@ -101,7 +126,7 @@ func main() {
// Test 3.2 Cycle
CreateCycle(head)
- if CheckCycle(head) == true {
+ if CheckCycleSimplified(head) == true {
fmt.Println("has Cycle")
} else {
fmt.Println("No Cycle")
@@ -114,7 +139,7 @@ func main() {
head = InsertNode(node, head)
}
// Test 4.1
- if CheckCycle(head) == true {
+ if CheckCycleSimplified(head) == true {
fmt.Println("has Cycle")
} else {
fmt.Println("No Cycle")
@@ -122,7 +147,7 @@ func main() {
// Test 4.2 Cycle
CreateCycle(head)
- if CheckCycle(head) == true {
+ if CheckCycleSimplified(head) == true {
fmt.Println("has Cycle")
} else {
fmt.Println("No Cycle")
diff --git a/longest_substr/main.go b/longest_substr/main.go
index 95f1871..0ac08cd 100644
--- a/longest_substr/main.go
+++ b/longest_substr/main.go
@@ -4,6 +4,9 @@ import (
"fmt"
)
+// Problem - def
+// Find the lomgest substr from a given string
+
func getLen(s string) int {
counter := make(map[rune]int, 0)
for _, r := range s {
diff --git a/micro-service/client b/micro-service/client
index 91ad73b..c85dc70 100755
Binary files a/micro-service/client and b/micro-service/client differ
diff --git a/micro-service/server b/micro-service/server
index 3d5143e..ee7d5ce 100755
Binary files a/micro-service/server and b/micro-service/server differ