본문 바로가기

알고리즘55

[프로그래머스] 숫자 문자열과 영단어 JAVA 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 📌 문제 네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다. 다음은 숫자의 일부 자릿수를 영단어로 바꾸는 예시입니다. 1478 → "one4seveneight" 234567 → "23four5six7" 10203 → "1zerotwozero3" 이렇게 숫자의 일부 자릿수가 영단어로 바뀌어졌거나, 혹은 바뀌지 않고 그대로인 문자열 s가 매개변수로 주어집니다. s가 의미하는 원래 숫자를 return 하도록.. 2022. 12. 19.
[LeetCode]007. Reverse Integer JAVA Reverse Integer - 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 📌 문제 Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. Assume the environment does not a.. 2022. 12. 19.
[LeetCode]005. Longest Palindromic Substring JAVA Longest Palindromic Substring - 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 📌 문제 Given a string s, return the longest palindromic substring in s. 📌 방법 반복문을 통해 문자열의 길이만큼 반복 그 안에서 반복되는 문자열 중 가장 긴 문자열을 출력 팰린드롬은 거꾸로 읽어도 제대로 읽는 것과 같은 낱말, 숫자, 문자열 따라서 반으로 접었을 때에, 양 옆이 같음. 때문에 반복문을 통해 .. 2022. 12. 19.
[LeetCode] 003. Longest Substring Without Repeating Characters JAVA Longest Substring Without Repeating Characters - 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 📌 문제 Given a string s, find the length of the longest substring without repeating characters. 📌 방법 컬렉션을 이용하여 풀이 그 중에서 Set의 HashSet을 이용하여 풀이 1️⃣ 최댓값 max 선언 및 초기화 2️⃣ HashSet을 이용하여 풀이 3️⃣.. 2022. 12. 16.
[LeetCode] 002. Add Two Numbers JAVA Add Two Numbers - 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 📌 문제 You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as.. 2022. 12. 16.
[백준 알고리즘] 5597. 과제 안 내신 분..? 📎 JAVA로 풀었습니다. 5597번: 과제 안 내신 분..? X대학 M교수님은 프로그래밍 수업을 맡고 있다. 교실엔 학생이 30명이 있는데, 학생 명부엔 각 학생별로 1번부터 30번까지 출석번호가 붙어 있다. 교수님이 내준 특별과제를 28명이 제출했는데, www.acmicpc.net 📌 문제 X대학 M교수님은 프로그래밍 수업을 맡고 있다. 교실엔 학생이 30명이 있는데, 학생 명부엔 각 학생별로 1번부터 30번까지 출석번호가 붙어 있다. 교수님이 내준 특별과제를 28명이 제출했는데, 그 중에서 제출 안 한 학생 2명의 출석번호를 구하는 프로그램을 작성하시오. 📌 방법 인덱스가 30이고, 길이가 31일 배열을 생성 28개의 들어오는 값에 해당하는 인덱스의 숫자를 1로 변환 반복문으로 돌리며 1이 아닌 배.. 2022. 12. 15.
[LeetCode] 001. Two Sum JAVA 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 📌 문제 Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same elem.. 2022. 12. 15.
[백준 알고리즘] 문제 25501번 : 재귀의 귀재 https://www.acmicpc.net/problem/25501 25501번: 재귀의 귀재 각 테스트케이스마다, isPalindrome 함수의 반환값과 recursion 함수의 호출 횟수를 한 줄에 공백으로 구분하여 출력한다. www.acmicpc.net 1. 힌트를 참고하자 public class Main{ public static int recursion(String s, int l, int r){ if(l >= r) return 1; else if(s.charAt(l) != s.charAt(r)) return 0; else return recursion(s, l+1, r-1); } public static int isPalindrome(String s){ return recursion(s, 0,.. 2022. 10. 6.
[알고리즘] LSCS 알고리즘 Largest Sum Contiguous Subarray (Kadane's Algorithm) - GeeksforGeeks Maximum sum contiguous subarray within a one-dimensional array of numbers using Kadane's Algorithm www.geeksforgeeks.org LSCS Largest Sum of Contiguous Subarray. 주어진 배열의 연속된 부분 배열의 합을 구한다고 할 때, 이중 가장 큰 값을 구하는 알고리즘이다. 1. 문제의 흐름을 생각해보자. int[] arr = { -2, -3, 4, -1, -2, 1, 5, -3 }; 정수 배열 arr이 위라고 가정을 하고 접근해보자. 여기서 구하는 값은 배열 arr의 합.. 2022. 10. 5.
[백준 알고리즘] 문제 2869번 : 달팽이는 올라가고 싶다(JAVA) https://www.acmicpc.net/problem/2869 2869번: 달팽이는 올라가고 싶다 첫째 줄에 세 정수 A, B, V가 공백으로 구분되어서 주어진다. (1 ≤ B < A ≤ V ≤ 1,000,000,000) www.acmicpc.net 1. 수식을 생각해보자. 1️⃣ A : 낮에 달팽이가 올라갈 수 있는 길이 2️⃣ B : 밤에 달팽이가 미끌어지는 길이 3️⃣ V : 달팽이가 올라갈 막대기의 길이 4️⃣ X : 올라가는 데에 걸리는 기간(날짜) // 1일차 낮 V = A // 2일차 낮 V = A - B + A // 3일차 낮 V = A - B + A - B + A // 4일차 낮 V = A - B + A - B + A - B + A 낮으로 기준을 잡은 이유는 낮에 마지막으로 올라가면 .. 2022. 10. 4.
[백준 알고리즘] 문제 4673번 : 셀프 넘버 (JAVA) 문제 링크 : https://www.acmicpc.net/problem/4673 4673번: 셀프 넘버 셀프 넘버는 1949년 인도 수학자 D.R. Kaprekar가 이름 붙였다. 양의 정수 n에 대해서 d(n)을 n과 n의 각 자리수를 더하는 함수라고 정의하자. 예를 들어, d(75) = 75+7+5 = 87이다. 양의 정수 n이 주어졌을 때, www.acmicpc.net 1. 셀프 넘버를 찾자. 1️⃣ n이라는 정수를 파라미터로 받는 selfNum 함수를 만듦. public static int selfNum(int n){} 2️⃣ sum의 초기값을 n으로 설정. : 셀프 넘버를 구하는 식을 살펴 보면, n값에 각 자리 수를 더하기 때문이다. (예 : d(15) = 15 + 1 + 5) public s.. 2022. 8. 23.
[백준 알고리즘] 문제 10718 Q. ACM-ICPC 인터넷 예선, Regional, 그리고 World Finals까지 이미 2회씩 진출해버린 kriii는 미련을 버리지 못하고 왠지 모르게 올해에도 파주 World Finals 준비 캠프에 참여했다. 대회를 뜰 줄 모르는 지박령 kriii를 위해서 격려의 문구를 출력해주자. 출력 ) 두 줄에 걸쳐 "강한친구 대한육군"을 한 줄에 한 번씩 출력한다. 풀어 보기 + IntelliJ 돌려보기 ) public class Test10718{ public static void main(String[] args){ System.out.println("강한친구 대한육군"); System.out.println("강한친구 대한육군"); } } ※ 백준 알고리즘은 Main.java 임. 2022. 7. 28.