This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* type ListNode struct { | |
* Val int | |
* Next *ListNode | |
* } | |
*/ | |
func deleteNode(node *ListNode) { | |
node.Val = node.Next.Val | |
node.Next = node.Next.Next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isAnagram(s string, t string) bool { | |
var message Text | |
json.Unmarshal(data, &message) | |
if len(s) != len(t) && len(t) > int(math.Pow(10, 4) * 5) || len(s) < 1 { | |
return false | |
} | |
for i := 0 ; i < len(s) ; i++{ | |
isChExsist := false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func firstUniqChar(s string) int { | |
for i:= 0 ; i < len(s) ; i++ { | |
ch := string(s[i]) | |
isUnique := true | |
for j:= 0 ; j < len(s); j++ { | |
if j != i && string(s[j]) == ch { | |
isUnique = false | |
break | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func reverse(x int) int { | |
if x < int(math.Pow(-2, 31)) || x > int(math.Pow(2, 31)) { | |
return 0 | |
} | |
xStr := strconv.Itoa(x) | |
reversedNumber := "" | |
// Remove the negative sign |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func reverseString(s []byte) { | |
for i, j:= 0, len(s)-1 ; i < j && i < len(s) ; i,j= i+1, j-1 { | |
s[i], s[j] = s[j], s[i] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. | |
*/ | |
func twoSum(nums []int, target int) []int { | |
var indices []int | |
for i:=0 ; i < len(nums) ; i++ { | |
for j:=i+1; j < len(nums);j++ { | |
if nums[j] + nums[i] == target { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
You are given a large integer represented as an integer array digits, | |
where each digits[i] is the ith digit of the integer. | |
The digits are ordered from most significant to least significant in left-to-right order. | |
The large integer does not contain any leading 0's. | |
*/ | |
func plusOne(digits []int) []int { | |
digitsStr := "" | |
for i:= 0 ; i < len(digits) ; i++ { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func containsDuplicate(nums []int) bool { | |
for i:= 0 ; i < len(nums) ; i++ { | |
n := nums[i] | |
for j:= 0; j < len(nums) ; j++ { | |
if j != i && nums[j] == n { | |
return true | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func rotate(nums []int, k int) { | |
l := len(nums) | |
k = k % l | |
newNums := append(nums[l-k:l], nums[0:l-k]...) | |
copy(nums,newNums) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"errors" | |
"log" | |
) | |
func Check(err error) { | |
if err != nil { |