tuter77

2023.01.01 알고리즘 현재까지 한것. 본문

Algorism TIL

2023.01.01 알고리즘 현재까지 한것.

tuter77 2023. 1. 1. 13:49

<프로그래머스>

  • 크기가 작은 부분문자열 
  • 조건에 맞는 도서리스트 출력하기
  • 문자열 나누기
  • 햄버거 만들기
  • 인기있는 아이스크림
  • 흉부외과 또는 일반외과 의사 목록 출력하기
class Solution {

    public static int solution(String t, String p) {
        int len = p.length();
        long num = Long.parseLong(p);//문자열을 Long으로 저장하는 parseLong
        int answer = 0;

        for (int i = 0; i <= t.length() - len; i++) {
            if (Long.parseLong(t.substring(i, i + len)) <= num) {//문자열 잘라서 꺼내는 substring(시작, 끝)
                answer++;//p자리만큼의 t의 값이 p의 길이보다 같거나 작으면 answer를 증가.
            }
        }

        return answer;
    }
}
SELECT book_id, date_format(PUBLISHED_DATE, '%Y-%m-%d') as PUBLISHED_DATE
from book
where category = '인문'
and date_format(PUBLISHED_DATE, '%Y') = '2021'
order by PUBLISHED_DATE asc
class Solution {
    public int solution(String s) {
        int answer = 0;

        while (s.length() != 0) {
            answer++;

            char ch = s.charAt(0);
            int sCount = 1;
            int dCount = 0;
            for (int i = 1; i < s.length(); i++) {
                if (ch == s.charAt(i))
                    sCount++;
                else
                    dCount++;

                if (sCount == dCount)
                    break;
            }

            s = s.substring(sCount + dCount);
        }

        return answer;
    }
}
import java.util.*;

class Solution {
    public int solution(int[] ingredient) {
        int answer = 0;
        int[] arr = new int []{1,2,3,1};
        ArrayList<Integer> checkList = new ArrayList<>();
        
        for(int i = 0; i<ingredient.length; i++){
            checkList.add(ingredient[i]);
            
            if (checkList.size() >=4){
                int[] temp = new int[4];
                temp[0] = checkList.get(checkList.size() - 4 );
                temp[1] = checkList.get(checkList.size() - 3 );
                temp[2] = checkList.get(checkList.size() - 2 );
                temp[3] = checkList.get(checkList.size() - 1 );
                
                if(Arrays.equals(temp, arr)){
                    answer++;
                    checkList.remove(checkList.size() - 1);
                    checkList.remove(checkList.size() - 1);
                    checkList.remove(checkList.size() - 1);
                    checkList.remove(checkList.size() - 1);
                }
            }
        }
        return answer;
    }
}
SELECT FLAVOR 
from first_half
order by total_order desc, shipment_id asc
SELECT DR_NAME, DR_ID, MCDP_CD, date_format(HIRE_YMD, '%Y-%m-%d') as HIRE_YMD
from doctor
where MCDP_CD = "cs" or MCDP_CD = "gs"
order by hire_ymd desc, dr_name asc