[프로그래머스] 120921 문자열 밀기 / 문제분석 / Java, Python3 정답

programmers

쉬운 문제라도 문제를 푸는 방법은 다양합니다.

더 명확하고 깔끔한 문제 해결 방법을 아신다면 자유롭게 말씀해주세요.

프로그래머스 120921 문자열 밀기

프로그래머스 저작권을 침해하지 않기 위해

문제 보시고 싶으시면 버튼을 눌러주세요.

답변 형식
프로그래머스 120921 자바
프로그래머스 120921 자바

문자열 A, B를 받아 문자열 A의 마지막 문자를 제일 앞으로 옮기는 행동을 몇 번 실행해야 B가 되는지 세면 됩니다.

풀이 조건

 문자열 관련 함수를 알고 있는지 묻는 문제입니다.

– 문자열은 숫자와 다르게 주소값을 가지고 있어

    자료의 값을 비교할 때는 

     Java에서는 “==” 대신 “equals” 함수를

     Python에서는 is를 쓸 수 없고 “==” 을 사용해야한다는 것이 중점입니다.

    ex) String A = “안녕하세요”  일 때 A의 주소값은 11(원래 주소값과 형식이 다름 예시로 봐주세요) 이고 값은 “안녕하세요” 이다.

– 문자열 자르기 함수를 알고 있어야 한다.

class Solution {
    public int solution(String A, String B) {
        if(A.equals(B)) return 0;

        for(int i=1; i<A.length(); i++){
            A = A.substring(A.length()-1)+A.substring(0,A.length()-1);
            if(B.equals(A)) return i;
        }
       
        return –1;
    }
}
class Solution {
    public int solution(String A, String B) {
        if(A.equals(B)) return 0;

        for(int i=1; i<A.length(); i++){
            A = A.substring(A.length()-1)+A.substring(0,A.length()-1);
            // A = A 마지막 글자 + A의 첫번째부터 마지막 바로 전 글자
            if(B.equals(A)) return i;
        }
       
        return –1;
    }
}
def solution(A, B):
    if A == B : return 0

    for i in range(len(A)) :
        A = A[-1]+A[0:len(A)-1]
        if A == B : return i+1

    return –1
def solution(A, B):
    if A == B : return 0

    for i in range(len(A)) :
        A = A[-1]+A[0:len(A)-1]
        # A = A 마지막 글자 + A의 첫번째부터 마지막 바로 전 글자
        if A == B : return i+1

    return –1

“[프로그래머스] 120921 문자열 밀기 / 문제분석 / Java, Python3 정답”의 87개의 댓글

  1. [1092]MX1888 México: Casino Online y Apuestas Deportivas | Registro y Login,Únete a MX1888 México, la plataforma líder en casino online y apuestas deportivas. Regístrate hoy para disfrutar de los mejores juegos, cuotas competitivas y un login rápido y seguro. ¡Vive la emoción del juego en MX1888! visit: mx1888

  2. [9318]5777bdt Official Login | সেরা অনলাইন স্লট ও দ্রুত বিকাশ পেমেন্ট,5777bdt অফিসিয়াল লগইন করে সেরা অনলাইন স্লট গেমস উপভোগ করুন। দ্রুত বিকাশ পেমেন্ট এবং সহজ নিয়মে খেলার অভিজ্ঞতা নিতে আজই অ্যাপ ডাউনলোড করুন। visit: 5777bdt

  3. [8258]fairplaycricket অ্যাকাউন্ট খোলা ও লাইভ ক্যাসিনো গেম খেলুন,fairplaycricket account খোলা এখন খুব সহজ। বিকাশ দিয়ে ক্যাসিনো ডিপোজিট করে সেরা অনলাইন স্লট গেম ও লাইভ ক্যাসিনো উপভোগ করতে আজই অ্যাপ ডাউনলোড করুন। visit: fairplaycricket

  4. [3822]valleybet লগইন এবং অ্যাপ ডাউনলোড – বিকাশ ক্যাসিনো ডিপোজিট,valleybet-এ লগইন করে অনলাইন স্লট গেম খেলার নিয়ম জানুন। বিকাশ দিয়ে ক্যাসিনো ডিপোজিট করে লাইভ ক্যাসিনো বোনাস অফার বুঝে নিন। আজই জয়েন করুন। visit: valleybet

  5. I was a bit skeptical at first but the welcome bonus actually works exactly as advertised. The interface is super friendly for newcomers and the payout speed made me smile all week. Trust the hype and join the fun at 5557bet

  6. Bingo night just got a whole lot better thanks to this wonderful platform. The room atmosphere is so lively and the power ups keep the excitement going round after round. I really appreciate how fair the RNG system is since I always play with a clear head. Come join the fun and discover why regulars keep raving about your chances here. phbingo8

댓글 달기

이메일 주소는 공개되지 않습니다.