Skip to content

Commit

Permalink
feat: solve problem 206
Browse files Browse the repository at this point in the history
  • Loading branch information
orgball2608 committed Jul 24, 2024
1 parent 9527e2a commit f3c82c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 27 additions & 0 deletions Easy/206. Reverse Linked List.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package easy

// ListNode Definition for singly-linked list.
type ListNode struct {
Val int
Next *ListNode
}

func reverseList(head *ListNode) *ListNode {
if head == nil {
return nil
}

var revHead *ListNode

for head != nil {
temp := head.Next
head.Next = revHead
revHead = head
head = temp
}

return revHead
}

//Time: O(N)
//Space: O(1)
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ func maximumSubarraySum(nums []int, k int) int64 {
return 0
}
frequency := make(map[int]int)
start, sum, max_sum := 0, 0, 0
start, sum, maxSum := 0, 0, 0
for i, val := range nums {
frequency[val]++
sum += val
if i-start+1 == k {
if len(frequency) == k {
max_sum = max(max_sum, sum)
maxSum = max(maxSum, sum)
}

if frequency[nums[start]] == 1 {
Expand All @@ -25,5 +25,5 @@ func maximumSubarraySum(nums []int, k int) int64 {
}
}

return int64(max_sum)
return int64(maxSum)
}

0 comments on commit f3c82c8

Please sign in to comment.