반응형

go 15

[leetcode] 49.Group Anagrams

문제 Given an array of strings, group anagrams together. Example: Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat","tan"], ["bat"] ] Note: All inputs will be in lowercase. The order of your output does not matter. 풀이 Anagram 은 단어나 문장을 구성하고 있는 문자의 순서를 바꾸어 다른 단어나 문장을 만드는 놀이이다. 주어진 input에서 Anagram 인 것들만 모아주면 되는 문제이다. input이 모두 소문자이기 떄문에 대소문자를 구분할 필요가 없다. map를 이..

알고리즘 2020.08.24

[leetcode] 240. Search a 2D Matrix II

문제 Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from top to bottom. Example : Consider the following matrix: ] Given target = 5, return true. Given target = 20, return false. 풀이 주어진 matrix에서 target 값이 존재하는 지를 찾는 문..

알고리즘 2020.08.23

[Golang] JSON 다루기

Go에서는 json 패키지 이용해서 JSON 데이터를 읽고 쓸 수 있다. 오늘은 Go 구조체와 json 패키지를 이용해 JSON 데이터를 읽고 쓰는 방법에 대하여 정리하겠다. 먼저 Go의 json 패키지에 있는 두 함수에 대하여 알아보자. 마샬링과 언마샬링 마샬링 Go 자료형을 JSON 데이터로 변경합니다. Marshal 함수를 사용한다. func Marshal(v interface{}) ([]byte, error) 언마샬링 마샬링과 반대로 JSON 데이터를 Go 자료형으로 변환합니다. Unmarshal 함수를 이용한다. func Unmarshal(data []byte, v interface{}) error 이제부터 예제를 통해 Go에서 JSON 다루는 방법에 대하여 알아보자. Simple JSON 우선..

Go 2020.08.09
반응형