전체 글

전체 글

    뉴스 클러스터링→isalpha(), str1[i:i+2], set(), count()★★

    나의 풀이 import re def solution(str1, str2): str1=str1.upper() str2=str2.upper() list_str1=[] list_str2=[] for i in range(len(str1)-1): if str1[i:i+2].isalpha(): list_str1.append(str1[i:i+2]) for i in range(len(str2)-1): if str2[i:i+2].isalpha(): list_str2.append(str2[i:i+2]) hap=0 gyo=0 list_str1과 list_str2에서 가장 중복되지 않는 순수한 요소로만 set을 구성한다. for s in set(list_str1+list_str2): gyo +=min(list_str1.cou..

    프린터★→ 순서쌍을 사용X, 기능개발과 유사★★+while(true)

    나의 풀이 class Solution { public int solution(int[] priorities, int location) { //jobs를 전체 출력물의 개수를 의미한다. int jobs= priorities.length; // cursor는 이동하는 위치표시기를 의미한다. int cursor=0; //answer는 출력횟수를 의미한다. int answer=0; while(true){ int max = priorities[0]; // 가장 큰 값을 저장할 변수, 초기값은 첫 번째 요소 for (int i = 1; i max) { max = priorities[i]; // 가장 큰 값을 찾으면 max 변수 값..

    int 배열에서 가장 큰 값을 찾는 방법

    1.Stream을 이용하는 경우 int[] array = {1, 5, 2, 8, 9, 3}; int max = Arrays.stream(array) .max() .orElse(0); // 0은 가장 큰 값이 없을 경우의 기본값 ▶ 스트림을 생성한 후, max() 메소드를 사용해서 가장 큰 값을 찾습니다. 이 메소드는 OptionalInt 객체를 반환합니다. ▶ OptionalInt는 가장 큰 값이 있을 수도 있고 없을 수도 있기 때문입니다. 이를 처리하기 위해 orElse(0) 메소드를 사용해서 가장 큰 값이 없을 경우의 기본값을 지정할 수 있습니다. 2. for문을 가지고 순회하는 경우 int[] array = {1, 5, 2, 8, 9, 3}; int max = array[0]; // 가장 큰 값을 ..

    프린터 → 응급실(큐)+리스트 컴프리핸션 + enumerate()+ any()★★

    나의 풀이 from collections import deque def solution(priorities, location): #priorities의 val은 우선순위를 나타낸다. #우선순위가 높을 수록 먼저 출력된다. #enumerate메서드를 써서 location을 구현하였다. #location의 요소는 대기목록의 위치를 의미한다. 주의할 점은 #0이면 위치가 첫번째이고, 1이면 위치가 두 번째이다. Q =[ (pos, val) for pos, val in enumerate(priorities)] Q=deque(Q) #deque([(0, 2), (1, 1), (2, 3), (3, 2)]) #0번째 문서는 우선순위가 2이고, 1번째 문서는 우선순위가 1이고, 2번째 문서는 우선순위가 3이다. #우선순..