Error rendering WebPanel: No renderer found for resource type: velocity Template contents: <meta name="ajs-keyboardshortcut-hash" content="$keyboardShortcutManager.shortcutsHash">
메타 데이터의 끝으로 건너뛰기
메타 데이터의 시작으로 이동
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)
    return cnts == sorted(cnts, reverse=True)
  • python battery included 만세


ref


  • 레이블 없음