고구마와 감자
Amor DevFati(아모르 개발파티)
고구마와 감자
전체 방문자
오늘
어제
  • 분류 전체보기
    • 스프링
    • 알고리즘
      • 백준
      • 프로그래머스
      • 인프런_자바코테강의
      • 리트코드
      • 해커랭크
      • 코드업
      • 이것저것
    • 자바
    • GIT
    • 파이썬
    • 개발이론
    • JPA
    • 김영한 강의
      • 모든 개발자를 위한 HTTP 웹 기본 지식
      • 스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술
      • 스프링 핵심 원리 - 기본편
    • 일기 및 아무말 적기

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 5361
  • 더하기 3
  • 14656
  • 남욱이의 닭장
  • 5988
  • 1598
  • 16673
  • 2의 제곱인가
  • 고려대학교에는 공식 와인이 있다
  • 백준
  • 2857
  • 꼬리를 무는 숫자 나열
  • 11966
  • 11023
  • 홀수일까 짝수일까
  • 조교는 새디스트야!!
  • Mini Fantasy War
  • 10409
  • 전투 드로이드 가격
  • 2921

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
고구마와 감자

Amor DevFati(아모르 개발파티)

알고리즘/프로그래머스

프로그래머스 A로 B만들기

2022. 12. 10. 23:24

https://school.programmers.co.kr/learn/courses/30/lessons/120886

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 public int solution1(String before, String after) {
        int answer = 0;
        char[] arr = after.toCharArray();
        int[] count1 = new int[arr.length];
        int[] count2 = new int[arr.length];
        for (int i = 0; i < before.length(); i++) {
            char c = before.charAt(i);
            char d = after.charAt(i);
            for (int j = 0; j < arr.length; j++) {
                if (c == arr[j]) count1[j]++;
                if (d == arr[j]) count2[j]++;
            }
        }
        return Arrays.equals(count1, count2) ? 1 : 0;
}

 

다른 풀이

public int solution(String before, String after) {
        return isCheck(getList(before), getList(after)) ? 1 : 0;
    }

private boolean isCheck(List<Integer> first, List<Integer> second) {
    for (int i = 0; i < first.size(); i++) {
        if (first.get(i) != second.get(i)) {
            return false;
        }
    }
    return true;
}

// 문자의 빈도만 리스트로 반환, 문자는 없음
private List<Integer> getList(String str) {
    return Arrays.stream(str.split(""))
            .collect(Collectors.groupingBy(s -> s))
            .values()
            .stream()
            .map(List::size)
            .collect(Collectors.toList());
}

'알고리즘 > 프로그래머스' 카테고리의 다른 글

프로그래머스 OX 퀴즈  (0) 2022.12.10
프로그래머스 n의 배수 고르기  (0) 2022.12.10
프로그래머스 369게임  (0) 2022.12.10
프로그래머스 7의 개수  (0) 2022.12.10
프로그래머스 2차원으로 만들기  (0) 2022.12.10
    '알고리즘/프로그래머스' 카테고리의 다른 글
    • 프로그래머스 OX 퀴즈
    • 프로그래머스 n의 배수 고르기
    • 프로그래머스 369게임
    • 프로그래머스 7의 개수
    고구마와 감자
    고구마와 감자
    Amor DevFati는 김연자-Amor Fati에 Development(개발)의 Dev 를 첨가하여 만든 이름

    티스토리툴바