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
}
有疑问加站长微信联系(非本文作者)