Skip to content

Instantly share code, notes, and snippets.

View mumunuu's full-sized avatar

무무 mumunuu

  • Seoul, South Korea
  • 17:06 (UTC +09:00)
View GitHub Profile
@mumunuu
mumunuu / removeDuplicates.go
Last active January 5, 2021 14:30
algorithm(leetcode) Remove Duplicates from Sorted Array
func removeDuplicates(nums []int) int {
if len(nums) == 0 {
return 0
}
i := 0
j := 1
for j < len(nums) {
@mumunuu
mumunuu / rotateArray.go
Last active January 8, 2021 06:07
algorithm(leetcode) Rotate Array
package main
func main() {
rotate([]int{1, 2, 3, 4, 5, 6, 7}, 3) //output [5,6,7,1,2,3,4]
rotate([]int{-1, -100, 3, 99}, 2) //output [3,99,-1,-100]
}
func rotate(nums []int, k int) {
@mumunuu
mumunuu / containsDuplicate.go
Created January 8, 2021 06:32
algorithm(leetcode) Contains Duplicate
package main
import "fmt"
func main() {
fmt.Println(containsDuplicate([]int{1, 2, 3, 1})) //output true
fmt.Println(containsDuplicate([]int{1, 2, 3, 4})) //output false
fmt.Println(containsDuplicate([]int{1, 1, 1, 3, 3, 4, 3, 2, 4, 2})) //output true
}
@mumunuu
mumunuu / singleArray.go
Last active January 12, 2021 02:02
algorithm(leetcode) Single Array
func singleNumber(nums []int) int {
if len(nums) == 1 { //요소가 1개인 배열은 종료.
return nums[0]
}
sort.Ints(nums) //정렬하면 0번째 인덱스와 1번째 인덱스는 같은 값을 갖는다.
for i := 0; i+1 < len(nums); i = i + 2 {
@mumunuu
mumunuu / intersection.go
Created January 13, 2021 06:00
algorithm(leetcode) Intersection of Two Arrays II
func intersect(nums1 []int, nums2 []int) []int {
answer := make([]int, 0)
for _, v1 := range nums1 {
for k, v2 := range nums2 {
if v1 == v2 {
answer = append(answer, v1) //값이 있으면 추가.
@mumunuu
mumunuu / plusOne.go
Last active January 15, 2021 00:09
algorithm(leetcode) Plus One
func plusOne(digits []int) []int {
answer := make([]int, len(digits)) //빈 배열 생성
stringInt := intToString(digits) //int를 string으로
x, _ := new(big.Int).SetString(stringInt, 10)
y := big.NewInt(1)
n := x.Add(x, y) //plus one
@mumunuu
mumunuu / moveZeroes.go
Last active January 15, 2021 01:03
algorithm(leetcode) Move Zeroes
func moveZeroes(nums []int) {
//현재값이 0일 때, 다음 숫자가 0이 아닐때 바꿔준다.
for i := 0; i < len(nums); i++ {
if nums[i] == 0 {
for k := i + 1; k < len(nums); k++ {
if nums[k] != 0 {
nums[i] = nums[k]
nums[k] = 0
@mumunuu
mumunuu / twoSum.go
Created January 15, 2021 01:30
algorithm(leetcode) Two Sum
func twoSum(nums []int, target int) []int {
for i := 0; i < len(nums); i++ {
for k := i + 1; k < len(nums); k++ {
if nums[i]+nums[k] == target {
return []int{i, k}
}
}
}
return []int{}
@mumunuu
mumunuu / validSudoku.go
Created January 18, 2021 07:54
algorithm(leetcode) Valid Sudoku
func isValidSudoku(board [][]byte) bool {
//체크할 빈 배열을 생성
col, row, blk := make2DArray(), make2DArray(), make2DArray()
//해당 숫자가, 해당 포지션에 지나간적이 있는지 체크하면 된다.
for i := 0; i < 9; i++ {
for j := 0; j < 9; j++ { //값을 모두 체크
@mumunuu
mumunuu / rotateImage.go
Last active January 20, 2021 07:27
algorithm(leetcode) Rotate Image
func rotate(matrix [][]int) {
matrixLength := len(matrix)
for i := 0; i < matrixLength; i++ {
for j := i; j < matrixLength; j++ {
tmp := matrix[j][i]
matrix[j][i] = matrix[i][j]