题解 | #字符串变形#

字符串变形

http://www.nowcoder.com/practice/c3120c1c1bc44ad986259c0cf0f0b80e

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param s string字符串 
# @param n int整型 
# @return string字符串
#
class Solution:
    def trans(self , s: str, n: int) -> str:
        # write code here
        # so we need to flip the word and also lower to capital? we start the flipping from the empty string? 
        # step 1 loop and when it encounters space then call flipping method 
        # step 2 when all flipping is done. Then another parallel loop to revert the string
        
        # string is immutable but slicable. list is mutable and slicable 
        # dist is muttable and slicable, tuple is immutable and slicable?
        # user can fill in or concatenate string elments into the initialize empty string. But Not be able to 
        #change the element in the string that is already there.
        
        #Mutable sequences can be changed after creation. Some of Python’s mutable data types are: lists, byte           #arrays, sets, and dictionaries.
        # immutabel after creation, strings, tuple 
        #https://towardsdatascience.com/immutable-vs-mutable-data-types-in-python-e8a9a6fcfbdc
        
        ls=[0]*len(s)
        for i in range(len(s)):
            if s[i].islower():
                ls[i]=(s[i].upper())
            else:
                ls[i]=(s[i].lower())
        new_str=''
        cur = len(ls)
        for i in range(len(ls)-1,-1,-1):
            if ls[i]==' ':
                new_str=new_str + ''.join(ls[i+1:cur]) +' '
                cur= i # 
        new_str = new_str + ''.join(ls[:cur])
        return new_str
                
        
            
            
全部评论

相关推荐

05-12 17:00
门头沟学院 Java
king122:你的项目描述至少要分点呀,要实习的话,你的描述可以使用什么技术,实现了什么难点,达成了哪些数字指标,这个数字指标尽量是真实的,这样面试应该会多很多,就这样自己包装一下,包装不好可以找我,我有几个大厂最近做过的实习项目也可以包装一下
点赞 评论 收藏
分享
06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务