LeetCode Golang


本文摘自网络,作者,侵删。

26.删除排序数组中的重复项

func removeDuplicates(nums []int) int {
    for len(nums) == 0{
        return 0
    }
    left,right := 0,1
    for ;right<len(nums);right++{
        if nums[left] == nums[right]{
        continue
    }
    left++
    nums[left] = nums[right]
    }
    return left+1
}

1.两数之和

func twoSum(nums []int, target int) []int {
   for i:=0;i<len(nums)-1;i++{
       for j:=1;j<len(nums);j++{
           for (nums[i]+nums[j]) == target{
               return []int{i,j}
           }
       }
   }
   return nil
}

7.整数反转

func reverse(x int) int {
    var nums,newnums int
    a := x%10
    newnums = nums*10 + a
    nums = newnums
    x = x/10

    MaxInt32 := 1<<31-1
    MinInt32 := -1<<31
    if x>MaxInt32 || x<MinInt32{
        return 0
    }
    return nums
}

本文来自:简书

感谢作者:Jo1s

查看原文:LeetCode Golang

相关阅读 >>

Go-zero 是如何追踪你的请求链路?

bash getopt 使用

Golang的优势在哪里

聊聊cortex的readring

最新字节跳动面试题与岗位层级,绩效考核制度介绍

Go语言操作数据库及其常规操作

Golang如何判断字符串是否为空

聊聊dubbo-Go-proxy的consulregistryload

Golang如何封装路由

Golang中哪些值是不可以寻址的

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...