Algorithms
-
프로그래머스 - 타겟 넘버 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 17:51
문제 링크 : 타겟 넘버 코딩테스트 연습 - 타겟 넘버 n개의 음이 아닌 정수들이 있습니다. 이 정수들을 순서를 바꾸지 않고 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 programmers.co.kr 정답 1. 재귀 : dfs함수가 int를 리턴하는 풀이 class Solution { public int solution(int[] numbers, int target) { int answer = 0; answer = dfs(numbers, 0, 0, target); return answer; } private int dfs(int[] numbers, int nodeNum, int sum, int target){ ..
-
LeetCode - two sumAlgorithms/- LeetCode 2022. 1. 29. 23:16
문제 링크 : two sum Two Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정답(Solution) class Solution { public int[] twoSum(int[] nums, int target) { //a + b 했을때 타겟을 만드는 코드 int loop = nums.length; int[] answer = new int[2]; //먼저 for문 돌면서 하나씩 하면 되네 for(int index1 = 0; index1 < loop;..
-
프로그래머스 - 신규 아이디 추천 [자바]Algorithms/- 프로그래머스 2022. 1. 29. 23:11
문제 링크 : 신규 아이디 추천 코딩테스트 연습 - 신규 아이디 추천 카카오에 입사한 신입 개발자 네오는 "카카오계정개발팀"에 배치되어, 카카오 서비스에 가입하는 유저들의 아이디를 생성하는 업무를 담당하게 되었습니다. "네오"에게 주어진 첫 업무는 새로 programmers.co.kr 정답 class Solution { public String solution(String new_id) { //1단계 소문자 치환 new_id = new_id.toLowerCase(); //2단계 알파벳 소문자, 숫자, 빼기(-), 밑줄(_), 마침표(.)를 제외한 문자를 제거 String temp_id = ""; char[] charArr = new_id.toCharArray(); for(char id : charArr)..