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 removeDuplicates(nums []int) int { | |
if len(nums) == 0 { | |
return 0 | |
} | |
i := 0 | |
j := 1 | |
for j < len(nums) { |
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 | |
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) { |
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" | |
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 | |
} |
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 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 { |
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 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) //값이 있으면 추가. |
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 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 |
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 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 |
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 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{} |
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 isValidSudoku(board [][]byte) bool { | |
//체크할 빈 배열을 생성 | |
col, row, blk := make2DArray(), make2DArray(), make2DArray() | |
//해당 숫자가, 해당 포지션에 지나간적이 있는지 체크하면 된다. | |
for i := 0; i < 9; i++ { | |
for j := 0; j < 9; j++ { //값을 모두 체크 |
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(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] |
OlderNewer