Skip to content

Commit 7c482e1

Browse files
committed
new file: bytedance/a替换函数.py
new file: bytedance/统计班级中的说谎者.py
1 parent 0838d6c commit 7c482e1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

bytedance/a替换函数.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def solution(s: str) -> str:
2+
s = s.replace("a", "%100")
3+
return s
4+
if __name__ == '__main__':
5+
print(solution(s="abcdwa") == '%100bcdw%100')
6+
print(solution(s="banana") == 'b%100n%100n%100')
7+
print(solution(s="apple") == '%100pple')
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import bisect
2+
3+
def solution(A):
4+
A.sort()
5+
ans = 0
6+
for i in range(len(A)):
7+
# 找到第一个大于A[i]的数的下标,用二分的库函数,类似于C++中的lower_bound
8+
index = bisect.bisect_left(A, A[i] + 1)
9+
if index - 1 >= len(A) - index:
10+
ans += 1
11+
return ans
12+
13+
14+
if __name__ == "__main__":
15+
# Add your test cases here
16+
print(solution([100, 100, 100]) == 3)
17+
print(solution([2, 1, 3]) == 2)
18+
print(solution([30, 1, 30, 30]) == 3)
19+
print(solution([19, 27, 73, 55, 88]) == 3)
20+
print(solution([19, 27, 73, 55, 88, 88, 2, 17, 22]) == 5)

0 commit comments

Comments
 (0)