@@ -4,11 +4,13 @@ import (
"fmt"
)
+// ListNode ...
type ListNode struct {
Val int
Next *ListNode
}
+// TreeNode ...
type TreeNode struct {
Left *TreeNode
@@ -1,9 +1,5 @@
package main
-import (
- "fmt"
-)
-
func minInt(x, y int) int {
if x < y {
return x
@@ -48,7 +44,7 @@ func maxArea(height []int) int {
return max
-func main() {
+/* func main() {
arr := []int{1, 2, 4, 54, 6, 54}
fmt.Println(maxArea(arr))
-}
+} */
func removeDuplicates(nums []int) int {
n := len(nums)
if n < 3 {
@@ -24,9 +20,9 @@ func removeDuplicates(nums []int) int {
return res
a1 := []int{0, 1, 1, 1, 2, 3, 3, 3}
fmt.Println(removeDuplicates(a1))
fmt.Println(a1)
fmt.Println(removeDuplicates([]int{}))
@@ -1,11 +1,7 @@
// ??? so many problems here
-func search(nums []int, target int) bool {
+/* func search(nums []int, target int) bool {
if len(nums) == 0 {
return false
@@ -45,9 +41,9 @@ func search(nums []int, target int) bool {
a1 := []int{4, 5, 6, 6, 6, 7, 7, 0, 0, 1, 1, 2, 2, 3}
fmt.Println(search(a1, 6))
fmt.Println(search(a1, 4))
@@ -59,4 +55,4 @@ func main() {
a3 := []int{3, 1}
fmt.Println(search(a3, 3))
fmt.Println(search(a3, 1))
@@ -1,16 +1,12 @@
// ListNode ...
-type ListNode struct {
+/* type ListNode struct {
-func list2str(head *ListNode) string {
+/* func list2str(head *ListNode) string {
curr := head
str := make([]rune, 0)
for curr != nil {
@@ -18,7 +14,7 @@ func list2str(head *ListNode) string {
curr = curr.Next
return string(str)
/**
* Definition for singly-linked list.
@@ -53,7 +49,7 @@ func deleteDuplicates(head *ListNode) *ListNode {
return dummy.Next
l15 := ListNode{5, nil}
l14 := ListNode{5, &l15}
l13 := ListNode{4, &l14}
@@ -61,4 +57,4 @@ func main() {
l1 := &ListNode{1, &l12}
fmt.Println(list2str(deleteDuplicates(l1)))
fmt.Println(list2str(deleteDuplicates(nil)))
@@ -55,7 +51,7 @@ func partition(head *ListNode, x int) *ListNode {
l14 := ListNode{0, &l15}
l13 := ListNode{6, &l14}
@@ -68,3 +64,4 @@ func main() {
l2 := &ListNode{1, &l22}
fmt.Println(list2str(partition(l2, 9)))
+*/
// generate gray code directly
func grayCodeOld(n int) []int {
res := make([]int, 1<<uint(n))
@@ -34,6 +30,6 @@ func grayCode(n int) (res []int) {
return
fmt.Println(grayCode(2))
@@ -5,7 +5,7 @@ import (
"sort"
-func combine(nums []int, k int) (res [][]int) {
+func combineWithDup(nums []int, k int) (res [][]int) {
if k == 0 || k == n {
row := make([]int, k)
@@ -14,11 +14,11 @@ func combine(nums []int, k int) (res [][]int) {
return append(res, row)
- for _, row := range combine(nums[:n-1], k-1) {
+ for _, row := range combineWithDup(nums[:n-1], k-1) {
row = append(row, nums[n-1])
res = append(res, row)
- res = append(res, combine(nums[:n-1], k)...)
+ res = append(res, combineWithDup(nums[:n-1], k)...)
@@ -26,12 +26,12 @@ func subsetsWithDup(nums []int) [][]int {
sort.Ints(nums)
res := [][]int{}
for i := 0; i <= len(nums); i++ {
- res = append(res, combine(nums, i)...)
+ res = append(res, combineWithDup(nums, i)...)
func main() {
- arr := []int{1, 3, 1}
+ arr := []int{1, 3, 1, 3}
fmt.Println(subsetsWithDup(arr))
@@ -1,14 +1,10 @@
func numDecodings(s string) int {
return 0
str := "12432546"
fmt.Println(numDecodings(str))