Skip to content

Commit

Permalink
new file: bytedance/a替换函数.py
Browse files Browse the repository at this point in the history
	new file:   bytedance/统计班级中的说谎者.py
  • Loading branch information
sakuralggm committed Nov 12, 2024
1 parent 0838d6c commit 7c482e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bytedance/a替换函数.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def solution(s: str) -> str:
s = s.replace("a", "%100")
return s
if __name__ == '__main__':
print(solution(s="abcdwa") == '%100bcdw%100')
print(solution(s="banana") == 'b%100n%100n%100')
print(solution(s="apple") == '%100pple')
20 changes: 20 additions & 0 deletions bytedance/统计班级中的说谎者.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import bisect

def solution(A):
A.sort()
ans = 0
for i in range(len(A)):
# 找到第一个大于A[i]的数的下标,用二分的库函数,类似于C++中的lower_bound
index = bisect.bisect_left(A, A[i] + 1)
if index - 1 >= len(A) - index:
ans += 1
return ans


if __name__ == "__main__":
# Add your test cases here
print(solution([100, 100, 100]) == 3)
print(solution([2, 1, 3]) == 2)
print(solution([30, 1, 30, 30]) == 3)
print(solution([19, 27, 73, 55, 88]) == 3)
print(solution([19, 27, 73, 55, 88, 88, 2, 17, 22]) == 5)

0 comments on commit 7c482e1

Please sign in to comment.