go
Leetcode - Gas Station
Leetcode - Gas Station
2024.03.02Problem There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations. Given two integer arrays gas and cost, return the starting gas station's index if you ..
합이 같은 부분집합(DFS : 아마존 인터뷰) - (golang)
합이 같은 부분집합(DFS : 아마존 인터뷰) - (golang)
2022.05.28문제 풀이 해당 문제는 subset(부분집합) 을 만들어서 전체 배열의 원소의 합을 2로 나누었을 때 부분집합 의 합과 똑같으면 YES 다르면 NO 를 출력 하는 방식으로 접근 해보았다. 먼저 부분집합을 만드는 방식에 있어서 해당 원소를 부분집합으로 포함 할지 안할지 이렇게 2진 트리로 재귀호출을 할수 있다. func SameSumSubSet(depth, sum int) { SameSumSubSet(depth+1, sum+array[depth]) SameSumSubSet(depth+1, sum) } depth 와 함께 sum 이라는 변수를 재귀호출 로 넘김으로써 depth 가 N 과 같아졌을때 총합 / 2 와 비교하기 위해서 사용한다. 첫번째 재귀 호출은 해당원소를 부분집합으로 사용하는 재귀호출이고 두번..
Go - Restful 하게 micro web service 만들기
Go - Restful 하게 micro web service 만들기
2021.10.10도메인에서 DB Table 1:1 구조체 만들기 저장소 Interface 만들기 해당 RepositoryDB 에 receive 함수 구현하기 DTO 정의하기 POST method 가 왔을 때 Request 로 받는 값 정의, Response 로 Client 에게 응답 값 정의 Service 구현 Service 는 Handler 를 통해 DTO(Request dto) 를 받아서 domain tpye 으로 repository 에 값을 처리하고 Response dto 로 Handler 에게 처리된 값을 넘긴다. Account Service Interface 구현 AccountService 는 Handler 에서 직접 구현 NewAccountService는 app.go 에서 Handler func로 사용 han..