[프로그래머스] 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 정답”의 70개의 댓글

  1. I stumbled upon this place by accident and now I check it daily before placing my wagers. The odds are competitive and I never had a single issue with my funds. It feels like a platform that genuinely cares about its community. lv66win

  2. I was hesitant about installing betting apps before but this one changed my mind completely. The security checks are solid and my personal data feels completely protected. Gaming on the move has never been this stress free. j77jdownload

  3. Downloading the app was so easy and it runs smoothly even on older phones. I love being able to place bets on the go without logging in every single time. The notification system keeps me updated on new tournaments and it just works great.

  4. [4617]maxwin Official Login | Trusted Online Casino Malaysia Fast Payout,maxwin provides a seamless gaming experience with an easy app download and convenient e-wallet casino deposits. Join now for secure play and fast payouts. visit: maxwin

  5. [4572]tgslot | Login Resmi Slot Gacor Hari Ini Deposit Dana Tanpa Potongan,tgslot menyediakan akses login resmi untuk main slot gacor hari ini. Download APK terbaru dan nikmati deposit Dana tanpa potongan. Daftar sekarang juga! visit: tgslot

  6. I have been exploring different gaming platforms lately and this one really stands out for me. The interface is super clean and I claimed my welcome bonus in no time. Customer support was also very helpful when I had a quick question about the withdrawal process. Definitely my new go to spot for evening sessions. surga88login

댓글 달기

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