当前位置:网站首页>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
相比之下你们更喜欢哪种呢?
边栏推荐
- 危化企业双预防机制数字化建设工作要求
- 2022 China Eye Expo, China Beijing International Children and Adolescent Eye Health Industry Exhibition
- 帮助安全红队取得成功的11条建议
- Significance Test--Study Notes
- uart_spi练习
- Likou Brush Question Record--Common Functions
- [ANT]apache ant 安装说明
- 企业从云服务的承诺支出中获得最大收益的四种方法
- 配置文件的读取-TOML
- The last exam before the NPDP revision!caution
猜你喜欢

【izpack】使用izpack为你的程序提供安装程序封装

企业从云服务的承诺支出中获得最大收益的四种方法

Summary of Database Design

力扣刷题记录8.1-----206. 反转链表

Mysql 5.7 into the pit

Redis - 时间序列数据类型的保存方案和消息队列实现

A40i gxl3680 ts_print报错:tslib: Selected device is not a touchscreen (must support ABS and KEY event

边缘计算的三个关键好处

力扣刷题记录10.1-----19. 删除链表的倒数第 N 个结点

数据库设计的总结
随机推荐
力扣刷题记录5.1-----59. 螺旋矩阵 II
Significance Test--Study Notes
JS 截取数组的最后几个元素
HCIP-R&S By Wakin自用笔记(3)OSPF之各类LSA及LSA更新规则
Appium常用操作及H5页面元素定位
腾讯地图获取定位
ROS2 ERROR: OpenGL 1.5 is not supported in GLRenderSystem::initialiseContext at C:\ci\ws\build...
MySQL/Oracle字符串分割
[ANT]apache ant 安装说明
JS 实现千分位分隔符
Cyclictest 简介 安装 测试
The most fierce "employee" in history, madly complaining about the billionaire boss Xiao Zha: So rich, he always wears the same clothes!
2022中国眼博会,中国北京国际儿童青少年眼睛健康产业展览会
2022/8/8 Competition thinking + state pressure dp
Data recovery software EasyRecovery supports recovery of all types of files
Etcd realize large-scale application service management of actual combat
2022 Eye Health Brand Franchise Exhibition, Beijing Vision Care Exhibition, China Ophthalmology Technology Summit
Analysis of when AuthenticationSuccessHandler is called after UsernameAuthenticationFilter is authorized successfully
力扣刷题记录3.1-----977. 有序数组的平方
连接数据库且在网页运行的RDLC