获得徽章 0
#青训营 x 字节后端训练营#
type Interface interface {
Discovery() discovery.DiscoveryInterface
AppsV1alpha1() appsv1alpha1.AppsV1alpha1Interface
AppsV1beta1() appsv1beta1.AppsV1beta1Interface
PolicyV1alpha1() policyv1alpha1.PolicyV1alpha1Interface
}
展开
评论
#青训营 x 字节后端训练营#
func removeZeroSumSublists(head *ListNode) *ListNode {
dummy := &ListNode{Val: 0}
dummy.Next = head
seen := map[int]*ListNode{}
prefix := 0
for node := dummy; node != nil; node = node.Next {
prefix += node.Val
seen[prefix] = node
}
prefix = 0
for node := dummy; node != nil; node = node.Next {
prefix += node.Val
node.Next = seen[prefix].Next
}
return dummy.Next
}
展开
评论
#青训营 x 字节后端训练营#
func twoSum(nums []int, target int) []int {
for i, x := range nums {
for j := i + 1; j < len(nums); j++ {
if x+nums[j] == target {
return []int{i, j}
}
}
}
return nil
}
展开
评论
#青训营 x 字节后端训练营#
package main

import "fmt"

func main() {
fmt.Println("Hello, World!")
}
展开
评论
#青训营 x 字节后端训练营#
package main_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = BeforeSuite(func() {

})

var _ = AfterSuite(func() {

})

func TestBpflet(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Bpflet Suite")
}
展开
评论
#青训营 x 字节后端训练营#
package utils

import (
"fmt"
"time"
)

func Retry(tryTimes int, trySleepTime time.Duration, action func() error) error {
var err error
for i := 0; i < tryTimes; i++ {
err = action()
if err == nil {
return nil
}

time.Sleep(trySleepTime * time.Duration(2*i+1))
}
return fmt.Errorf("retry action timeout: %v", err)
}
展开
评论
#青训营 x 字节后端训练营#
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Authors of KubeArmor

package main

import (
"fmt"

"github.com/sethvargo/go-githubactions"
)

func main() {
action := githubactions.New()
oldAppName := action.GetInput("old-app-image-name")
if oldAppName == "" {
action.Fatalf("old-app-image-name cannot be empty")
}
newAppName := action.GetInput("new-app-image-name")
if newAppName == "" {
action.Fatalf("new-app-image-name cannot be empty")
}
filepath := action.GetInput("filepath")

fmt.Printf("oldAppName: %v, newAppName: %v, filepath: %v", oldAppName, newAppName, filepath)
}
展开
评论
#青训营 x 字节后端训练营#
青训营打卡
评论
#青训营 x 字节后端训练营#
// ClusterRetained represents the filter to select clusters.
type ClusterRetained struct {
// LabelSelector is a filter to select member clusters by labels.
// If non-nil and non-empty, only the clusters match this filter will be selected.
// +optional
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`

// FieldSelector is a filter to select member clusters by fields.
// If non-nil and non-empty, only the clusters match this filter will be selected.
// +optional
FieldSelector *FieldSelector `json:"fieldSelector,omitempty"`

// ClusterNames is the list of clusters to be selected.
// +optional
ClusterNames []string `json:"clusterNames,omitempty"`

// ExcludedClusters is the list of clusters to be ignored.
// +optional
ExcludeClusters []string `json:"exclude,omitempty"`
}
展开
评论
#青训营 x 字节后端训练营#
hostConfig, err := hostClientConfig.ClientConfig()
if err != nil {
return nil, errors.Wrapf(err, "Unable to load configuration for cluster context %q in kubeconfig %q.`",
o.HostClusterContext, o.Kubeconfig)
}
展开
评论
#青训营 x 字节后端训练营# func maximumTastiness(price []int, k int) int {
sort.Ints(price)
left, right := 0, price[len(price)-1]-price[0]
for left < right {
mid := (left + right + 1) / 2
if check(price, k, mid) {
left = mid
} else {
right = mid - 1
}
}
return left
}

func check(price []int, k int, tastiness int) bool {
prev := int(math.Inf(-1)) >> 1
cnt := 0
for _, p := range price {
if p - prev >= tastiness {
cnt++
prev = p
}
}
return cnt >= k
}
展开
评论
#青训营 x 字节后端训练营# go语言每日一题
func min(a, b int) int {
if a < b {
return a
}
return b
}

func max(a, b int) int {
if a > b {
return a
}
return b
}

func mctFromLeafValues(arr []int) int {
n := len(arr)
dp, mval := make([][]int, n), make([][]int, n)
for i := 0; i < n; i++ {
dp[i] = make([]int, n)
mval[i] = make([]int, n)
}
for j := 0; j < n; j++ {
mval[j][j] = arr[j]
for i := j - 1; i >= 0; i-- {
mval[i][j] = max(arr[i], mval[i + 1][j])
dp[i][j] = 0x3f3f3f3f
for k := i; k < j; k++ {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + mval[i][k] * mval[k + 1][j])
}
}
}
return dp[0][n - 1]
}
展开
评论
#青训营 x 字节后端训练营# 每日一题
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func delNodes(root *TreeNode, to_delete []int) []*TreeNode {
toDeleted:=make(map[int]bool)
for _,val:= range to_delete {
toDeleted[val]=true
}
var ans []*TreeNode
var dfs func(node *TreeNode, is_root bool) *TreeNode
dfs=func(node *TreeNode, is_root bool) *TreeNode {
if node == nil {
return nil
}
deleted:=false
if toDeleted[node.Val] {
deleted=true
}
node.Left=dfs(node.Left,deleted)
node.Right=dfs(node.Right,deleted)
if deleted {
node=nil
} else {
if is_root {
ans=append(ans, node)
}
}
return node
}
dfs(root,true)
return ans
}
展开
评论
#青训营 x 字节后端训练营# go语言每日一题
func averageValue(nums []int) int {
sum:=0
cnt:=0
for _,num:= range nums {
if num % 6 == 0 {
sum+=num
cnt++
}
}
if cnt==0 {
return 0
}
return sum/cnt
}
展开
评论