Discuss / Python / 看了其他人的,我觉得我的从效率和资源来说都比较优的

看了其他人的,我觉得我的从效率和资源来说都比较优的

Topic source

UTOO_NAIVE

#1 Created at ... [Delete] [Delete and Lock User]
def trim(s):    idx = 0    begin_idx = None    end_idx = None    strLen = len(s)    while idx < strLen:        if begin_idx is None and s[idx] != ' ':            begin_idx = idx        if end_idx is None and s[strLen-idx-1] != ' ':            end_idx = strLen-idx        idx = idx + 1    if begin_idx is None and end_idx is None:        return ''    return s[begin_idx:end_idx]

UTOO_NAIVE

#2 Created at ... [Delete] [Delete and Lock User]
def trim(s):    idx = 0    begin_idx = None    end_idx = None    strLen = len(s)    while idx < strLen:        if begin_idx is None and s[idx] != ' ':            begin_idx = idx        if end_idx is None and s[strLen-idx-1] != ' ':            end_idx = strLen-idx        idx = idx + 1    if begin_idx is None and end_idx is None:        return ''    return s[begin_idx:end_idx]

UTOO_NAIVE

#3 Created at ... [Delete] [Delete and Lock User]
def trim(s):    idx = 0    begin_idx = None    end_idx = None    strLen = len(s)    while idx < strLen:        if begin_idx is None and s[idx] != ' ':            begin_idx = idx        if end_idx is None and s[strLen-idx-1] != ' ':            end_idx = strLen-idx        idx = idx + 1    if begin_idx is None and end_idx is None:        return ''    return s[begin_idx:end_idx]

UTOO_NAIVE

#4 Created at ... [Delete] [Delete and Lock User]

直接贴缩进乱掉了

def trim(s):
    idx = 0
    begin_idx = None
    end_idx = None
    strLen = len(s)
    while idx < strLen:
        if begin_idx is None and s[idx] != ' ':
            begin_idx = idx
        if end_idx is None and s[strLen-idx-1] != ' ':
            end_idx = strLen-idx
        idx = idx + 1
    if begin_idx is None and end_idx is None:
        return ''
    return s[begin_idx:end_idx]

  • 1

Reply