uncommited problems
This commit is contained in:
		@@ -31,10 +31,16 @@
 | 
				
			|||||||
	"containerUser": "vscode",
 | 
						"containerUser": "vscode",
 | 
				
			||||||
	"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/${localWorkspaceFolderBasename},type=bind,Z",
 | 
						"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/${localWorkspaceFolderBasename},type=bind,Z",
 | 
				
			||||||
	"runArgs": [
 | 
						"runArgs": [
 | 
				
			||||||
		"--userns=keep-id"
 | 
							"--userns=keep-id",
 | 
				
			||||||
 | 
							"--cap-add=SYS_PTRACE",
 | 
				
			||||||
 | 
							"--security-opt",
 | 
				
			||||||
 | 
							"seccomp=unconfined"
 | 
				
			||||||
	],
 | 
						],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"features": {
 | 
						"features": {
 | 
				
			||||||
		"rust": "latest"
 | 
							"rust": "latest",
 | 
				
			||||||
 | 
							"golang": "latest",
 | 
				
			||||||
 | 
							"python": "os-provided",
 | 
				
			||||||
 | 
							"node": "lts"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										27
									
								
								candy/sol.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								candy/sol.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func candy(ratings []int) int {
 | 
				
			||||||
 | 
						count := 1
 | 
				
			||||||
 | 
						for idx := 0; idx < len(ratings)-1; {
 | 
				
			||||||
 | 
							for idx < len(ratings)-1 && ratings[idx+1] == ratings[idx] {
 | 
				
			||||||
 | 
								count++
 | 
				
			||||||
 | 
								idx++
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							next_inc := 1
 | 
				
			||||||
 | 
							for idx < len(ratings)-1 && ratings[idx+1] > ratings[idx] {
 | 
				
			||||||
 | 
								next_inc++
 | 
				
			||||||
 | 
								idx++
 | 
				
			||||||
 | 
								count += next_inc
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							next_dec := 1
 | 
				
			||||||
 | 
							for idx < len(ratings)-1 && ratings[idx+1] < ratings[idx] {
 | 
				
			||||||
 | 
								count += next_dec
 | 
				
			||||||
 | 
								next_dec++
 | 
				
			||||||
 | 
								idx++
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if next_dec > next_inc {
 | 
				
			||||||
 | 
								count += next_dec - next_inc
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return count
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										30
									
								
								longest-consecutive-sequence/sol.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								longest-consecutive-sequence/sol.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func longestConsecutive(nums []int) (max int) {
 | 
				
			||||||
 | 
						exists := make(map[int]bool, len(nums))
 | 
				
			||||||
 | 
						for _, n := range nums {
 | 
				
			||||||
 | 
							exists[n] = true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						done := make(map[int]bool, len(nums))
 | 
				
			||||||
 | 
						for _, n := range nums {
 | 
				
			||||||
 | 
							if _, ok := done[n]; !ok {
 | 
				
			||||||
 | 
								done[n] = true
 | 
				
			||||||
 | 
								l := 1
 | 
				
			||||||
 | 
								for exists[n+1] {
 | 
				
			||||||
 | 
									l++
 | 
				
			||||||
 | 
									n++
 | 
				
			||||||
 | 
									done[n] = true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								n -= l - 1
 | 
				
			||||||
 | 
								for exists[n-1] {
 | 
				
			||||||
 | 
									l++
 | 
				
			||||||
 | 
									n--
 | 
				
			||||||
 | 
									done[n] = true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if l > max {
 | 
				
			||||||
 | 
									max = l
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return max
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "sort"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const M = 1000000007
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func maxArea(h int, w int, horizontalCuts []int, verticalCuts []int) int {
 | 
				
			||||||
 | 
						sort.Ints(horizontalCuts)
 | 
				
			||||||
 | 
						sort.Ints(verticalCuts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						hs, vs := len(horizontalCuts), len(verticalCuts)
 | 
				
			||||||
 | 
						maxH, maxW := horizontalCuts[0], verticalCuts[0]
 | 
				
			||||||
 | 
						horizontalCuts, verticalCuts = append(horizontalCuts, h), append(verticalCuts, w)
 | 
				
			||||||
 | 
						for i := 0; i < hs; i++ {
 | 
				
			||||||
 | 
							d := horizontalCuts[i+1] - horizontalCuts[i]
 | 
				
			||||||
 | 
							if d > maxH {
 | 
				
			||||||
 | 
								maxH = d
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for i := 0; i < vs; i++ {
 | 
				
			||||||
 | 
							d := verticalCuts[i+1] - verticalCuts[i]
 | 
				
			||||||
 | 
							if d > maxW {
 | 
				
			||||||
 | 
								maxW = d
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return (maxW * maxH) % M
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										20
									
								
								maximum-units-on-a-truck/sol.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								maximum-units-on-a-truck/sol.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "sort"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func maximumUnits(boxTypes [][]int, truckSize int) int {
 | 
				
			||||||
 | 
						sort.Slice(boxTypes, func(i, j int) bool {
 | 
				
			||||||
 | 
							return boxTypes[i][1] > boxTypes[j][1]
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						units := 0
 | 
				
			||||||
 | 
						count := 0
 | 
				
			||||||
 | 
						for idx := 0; idx < len(boxTypes); idx++ {
 | 
				
			||||||
 | 
							units += boxTypes[idx][0] * boxTypes[idx][1]
 | 
				
			||||||
 | 
							count += boxTypes[idx][0]
 | 
				
			||||||
 | 
							if count >= truckSize {
 | 
				
			||||||
 | 
								units -= (count - truckSize) * boxTypes[idx][1]
 | 
				
			||||||
 | 
								return units
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return units
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "sort"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func minDeletions(s string) int {
 | 
				
			||||||
 | 
						freq := make([]int, 26) // only lower-case english letters
 | 
				
			||||||
 | 
						for _, chr := range s {
 | 
				
			||||||
 | 
							freq[chr-'a']++
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						sort.Ints(freq)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						count, max := 0, len(s)
 | 
				
			||||||
 | 
						for idx := len(freq) - 1; idx >= 0 && freq[idx] != 0; idx-- {
 | 
				
			||||||
 | 
							f := freq[idx]
 | 
				
			||||||
 | 
							if f > max {
 | 
				
			||||||
 | 
								count += f - max
 | 
				
			||||||
 | 
								f = max
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if f > 0 {
 | 
				
			||||||
 | 
								max = f - 1
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								max = 0
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return count
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						println(minDeletions("bbcebab"))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										13
									
								
								number-of-steps-to-reduce-a-number-to-zero/sol.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								number-of-steps-to-reduce-a-number-to-zero/sol.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func numberOfSteps(num int) (steps int) {
 | 
				
			||||||
 | 
						for num != 1 {
 | 
				
			||||||
 | 
							if num%2 == 0 {
 | 
				
			||||||
 | 
								num /= 2
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								num--
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							steps++
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return steps
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					impl Solution {
 | 
				
			||||||
 | 
					    pub fn min_partitions(n: String) -> i32 {
 | 
				
			||||||
 | 
					        (n.bytes()
 | 
				
			||||||
 | 
					            .max()
 | 
				
			||||||
 | 
					            .unwrap() - b'0') as i32
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										15
									
								
								queue-reconstruction-by-height/sol.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								queue-reconstruction-by-height/sol.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "sort"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func reconstructQueue(people [][]int) [][]int {
 | 
				
			||||||
 | 
						sort.Slice(people, func(i, j int) bool {
 | 
				
			||||||
 | 
							return people[i][0] > people[j][0] || (people[i][0] == people[j][0] &&
 | 
				
			||||||
 | 
								people[i][1] < people[j][1])
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						for idx, p := range people {
 | 
				
			||||||
 | 
							copy(people[p[1]+1:idx+1], people[p[1]:idx+1])
 | 
				
			||||||
 | 
							people[p[1]] = p
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return people
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										17
									
								
								wiggle-subsequence/sol.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								wiggle-subsequence/sol.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func wiggleMaxLength(nums []int) int {
 | 
				
			||||||
 | 
						// Current's value only matters in terms of negative / 0 / positive.
 | 
				
			||||||
 | 
						// The numerical value doesn't get used and therefore can be messed with.
 | 
				
			||||||
 | 
						current, count := 0, len(nums)
 | 
				
			||||||
 | 
						for i := 0; i < len(nums)-1; i++ {
 | 
				
			||||||
 | 
							new := nums[i+1] - nums[i]
 | 
				
			||||||
 | 
							if (current > 0 && new > 0) || (current < 0 && new < 0) || new == 0 {
 | 
				
			||||||
 | 
								count--
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if new != 0 {
 | 
				
			||||||
 | 
								current = new
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return count
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user