行业知识
LeetCode 每日一题 数学篇 LCR 182.动态口令
2026-12-04 06:49:34
来源:互联网转载
某公司门禁密码使用动态口令技术。初始密码为字符串 password,密码更新均遵循以下步骤:
()- 设定一个正整数目标值 target
- 将 password 前 target 个字符按原顺序移动至字符串末尾
请返回更新后的密码字符串。
char* dynamicPassword(char* password, int target) { int n = strlen(password); char* ans = (char*)calloc(1, sizeof(char) * (n + 1)); strncpy(ans, password + target, n - target); strncpy(ans + n - target, password, target); return ans;}//思路:1.先把password里的字符存起来
// 2.再利用target把其中的前几个存起来并减去
// 3.把2存起来的放到减去的后面
总结:遇到字符型的 可以存储起来 利用数据结构
上一篇:如何在微信上下载两个文件