当前位置:网站首页>LintCode 146. 大小写转换 II
LintCode 146. 大小写转换 II
2022-08-09 02:23:00 【Leleprogrammer】
LintCode第146题:大小写转换II
解题思路:
这道题也是有两种方法进行解答,第一种还是用上一道题用的upper方法,第二种是进行字符的遍历,将需要改动的改动即可
直接上代码!
方法一(时间复杂度:O(1))
class Solution:
"""
@param letters: A string
@return: A string
"""
def lowercase_to_uppercase2(self, letters):
# write your code here
return letters.upper()
方法2(时间复杂度:O(n))
class Solution:
"""
@param letters: A string
@return: A string
"""
def lowercase_to_uppercase2(self, letters):
# write your code here
result=""
for letter in letters:
if ord(letter)>=97 and ord(letter)<=122:
result=result+chr(ord(letter)-32)
else:
result=result+letter
return result
相比之下你们更喜欢哪种呢?
边栏推荐
猜你喜欢
ROS2 ERROR: OpenGL 1.5 is not supported in GLRenderSystem::initialiseContext at C:\ci\ws\build...
Summary of pytorch related knowledge points
Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
通过安装VNC服务器x11vnc(或vnc4server)和配置x11vnc.service实现远程通过VNC-Viewer访问VNC服务器。
电磁辐射安全标准及检测方法
【izpack】使用izpack为你的程序提供安装程序封装
A40i gxl3680 ts_print报错:tslib: Selected device is not a touchscreen (must support ABS and KEY event
Etcd realize large-scale application service management of actual combat
线段树知识整理
配置文件的读取-TOML
随机推荐
My thoughts on software development
为什么应用程序依赖关系映射对于云迁移至关重要
【HNUMSC】C语言第二讲
力扣刷题记录1.5-----367. 有效的完全平方数
uart_spi练习
OJ:L3-001 凑零钱 DFS
MySQL/Oracle字符串分割
2022 Eye Health Brand Franchise Exhibition, Beijing Vision Care Exhibition, China Ophthalmology Technology Summit
Likou Brush Question Record--Common Functions
Redis - 时间序列数据类型的保存方案和消息队列实现
HNUMSC-C语言第一课
yii2的安装之路
2022/8/8 比赛思维+状压dp
MT4/MQL4 Getting Started to Mastering EA Tutorial Lesson 1 - MQL Language Common Functions (1) OrderSend() Function
The last exam before the NPDP revision!caution
JS 实现千分位分隔符
mysql 5.7 入坑
gpio子系统和pinctrl子系统(下)
ROS 、SLAM 学习 error整理
How to install yii2