日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

leetcode刷题报告 之hrt篇 oa leetcode 722 Remove Comments python

發布時間:2023/12/18 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 leetcode刷题报告 之hrt篇 oa leetcode 722 Remove Comments python 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Given a C++ program, remove comments from it. The program source is an array of strings source where source[i] is the ith line of the source code. This represents the result of splitting the original source code string by the newline character ‘\n’.

In C++, there are two types of comments, line comments, and block comments.

The string “//” denotes a line comment, which represents that it and the rest of the characters to the right of it in the same line should be ignored.
The string “/" denotes a block comment, which represents that all characters until the next (non-overlapping) occurrence of "/” should be ignored. (Here, occurrences happen in reading order: line by line from left to right.) To be clear, the string “/*/” does not yet end the block comment, as the ending would be overlapping the beginning.
The first effective comment takes precedence over others.

For example, if the string “//” occurs in a block comment, it is ignored.
Similarly, if the string “/*” occurs in a line or block comment, it is also ignored.
If a certain line of code is empty after removing comments, you must not output that line: each string in the answer list will be non-empty.

There will be no control characters, single quote, or double quote characters.

For example, source = “string s = “/* Not a comment. */”;” will not be a test case.
Also, nothing else such as defines or macros will interfere with the comments.

It is guaranteed that every open block comment will eventually be closed, so “/*” outside of a line or block comment always starts a new comment.

Finally, implicit newline characters can be deleted by block comments. Please see the examples below for details.

After removing the comments from the source code, return the source code in the same format.

這題 我愿意稱之為 字符串頂流題
這題看著不難,但坑很多。
先來弄清楚一些情況比如:
// abcdef /*
這里的/*是可以忽略的 就是一旦出現 “//“ 那//之后的內容都忽略

/* abc // 這也是一樣 // 是可以忽略的,一旦有/* 后面的內容都是comment直到 */出現

a/* hahaha **/b
或者
a/ * haha
haha */ b
的結果都是 ab
也就是說注釋符號前后的 內容我們是要保留的

同理
abc // eve
這里保留的是 abc

還有其他要素,要素過多
1 不要有typo, / * , * / 是左斜杠
2 這里直接去一整行判斷,比如 if /* in sentence,是不行的因為 可能一行可能同時含有 //, /* 和 * /
3 這里最棘手的就是 /* 因為受他影響, 一個普通的行也會被忽略,他是一個超越單行句子之外的影響因素,自然想到要設立一個flag來記錄是不是正被/*包裹
并且在遍歷每個字符串的時候 都要給這個flag做一次判斷

class Solution:def removeComments(self, source: List[str]) -> List[str]:ans = []star = Falsecontent = ""for s in source:# if in /* state, the content need be connected with content before /*if not star:content = ""i = 0 while i < len(s):# all use if elif, every judgement should have a star flagif s[i:i+2] == "/*" and not star:i+=1# need add one to jump this comment signalstar = Trueelif s[i:i+2] == "//" and not star:i += 1breakelif s[i:i+2] == "*/" and star:star = Falsei += 1elif not star:content += s[i]i += 1if content!="" and not star:ans.append(content)return ans

總結

以上是生活随笔為你收集整理的leetcode刷题报告 之hrt篇 oa leetcode 722 Remove Comments python的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 69色| 日本免费在线观看 | 在线观看av日韩 | 男女视频免费看 | 日本熟妇色xxxxx日本免费看 | 亚洲精品视频免费观看 | 国产精品一区二区三区免费看 | 久久性av | 青草青草视频 | 久久久久免费视频 | 善良的老师伦理bd中字 | 草色噜噜噜av在线观看香蕉 | 日本女教师电影 | 国产 日韩 欧美在线 | 最近中文字幕免费 | 日朝毛片| 污污内射久久一区二区欧美日韩 | 中文字幕一区二区三区手机版 | 国产精品午夜福利 | 久久久久在线观看 | 91av小视频 | 俺去俺来也在线www色官网 | 亚洲欧美日韩激情 | 日韩在线视频观看免费 | 免费观看理伦片在线播放视频软件 | 国产l精品国产亚洲区久久 午夜青青草 | 欧美黑人孕妇孕交 | 亚洲精品免费在线播放 | 免费观看美女裸体网站 | 亚洲伊人影院 | 免费黄色一级视频 | 在线国产一区二区 | jizz亚洲女人高潮大叫 | 手机av免费看 | 国产精品一级无码 | 九九在线观看高清免费 | 国产精品人人 | fc2ppv在线播放 | 黄色网在线播放 | 成年人免费在线观看 | 久久久久久一区二区 | 中国人妖和人妖做爰 | 电影桑叶2在线播放完整版 222aaa | 久久人人爽人人爽人人片av免费 | 伊人黄网| 欧洲国产精品 | 国产男男chinese网站 | 性猛交xxxx乱大交孕妇2十 | 五月婷婷av | 在线观看欧美成人 | 岛国久久久| 黄色一级网址 | 久久久久亚洲av片无码 | 深夜福利在线免费观看 | 激情欧美一区二区免费视频 | 精品美女久久久 | 张柏芝亚洲一区二区三区 | 最新高清无码专区 | 黄色网址www | 欧美日韩亚洲国产另类 | 日日噜噜噜 | 超碰在线9 | 亚洲天堂男人的天堂 | 欧美日韩一区二区三区在线观看 | 午夜动态图 | 亚洲4p| 亚洲精品三级 | 中文字幕日韩精品亚洲一区小树林 | 亚洲精品无amm毛片 国内一区二区三区 | 高h校园不许穿内裤h调教 | 精品国产乱码久久久久久婷婷 | 亚洲色图综合 | 窝窝午夜看片 | 日韩美女视频网站 | 亚州av一区 | 日本中文字幕视频在线 | 久久b| 成人日韩在线观看 | 精彩视频一区二区三区 | 色婷婷在线观看视频 | 正在播放国产精品 | 鲁在线视频 | 男女性网站 | 国产嫩草影院久久久久 | 涩涩99| 国产一级片中文字幕 | 日韩在线观看视频网站 | 欧美性极品xxxx做受 | 色呦呦网站在线观看 | 国产精品99无码一区二区视频 | 外国毛片 | 日本黄页网站免费大全 | 久久综合导航 | 国产精品久久久久久中文字 | 成人高清在线 | 国产91免费看 | 国精品一区二区三区 | av免费播放 | 91在线观看网站 |