Error rendering WebPanel: No renderer found for resource type: velocity Template contents: <meta name="ajs-keyboardshortcut-hash" content="$keyboardShortcutManager.shortcutsHash">
메타 데이터의 끝으로 건너뛰기
메타 데이터의 시작으로 이동

이 페이지의 이전 버전을 보고 있습니다. 현재 버전 보기.

현재와 비교 페이지 이력 보기

« 이전 버전 16 현재 »

live
def isBeautifulString(inputString):
    cnts = [0] * 26
    
    for c in inputString: 
        idx = ord(c)-97        
        cnts[idx] += 1
        
    return True if cnts[::-1] == sorted(cnts) else False
test case
testcases = {"bbbaacdafe": True,
             "aabbb": False, 
             "bbc": False, 
             "bbbaa" : False, 
             "abcdefghijklmnopqrstuvwxyzz": False, 
             "abcdefghijklmnopqrstuvwxyz": True, 
             "abcdefghijklmnopqrstuvwxyzqwertuiopasdfghjklxcvbnm": True, 
             "fyudhrygiuhdfeis": False, 
             "zaa": False, 
             "zyy": False,}

def test_solution(testcases) : 
    for t in testcases.keys():
        result = isBeautifulString(t)
        
        if testcases[t] != result:
            print(f"Wrong Case: {t} / expected: {testcases[t]} / your : {result}")
        
    print("Test Finished")


##  Refactoring

Refactoring
import string 

def isBeautifulString(inputString):
    cnts = [inputString.count(c) for c in string.ascii_lowercase]

    return cnts[::-1] == sorted(cnts)
  • python battery included 만세


ref


  • 레이블 없음