网站建设报价东莞,购物网站推广方案,网站开发实战第二章,东莞个人网站制作目录
1. 反转链表 II #x1f31f;#x1f31f;
2. 解码方法 #x1f31f;#x1f31f;
3. 擅长编码的小k #x1f31f;#x1f31f;#x1f31f;
#x1f31f; 每日一练刷题专栏 #x1f31f;
Golang每日一练 专栏
Python每日一练 专栏
C/C每日一练 专栏
…
目录
1. 反转链表 II
2. 解码方法
3. 擅长编码的小k 每日一练刷题专栏
Golang每日一练 专栏
Python每日一练 专栏
C/C每日一练 专栏
Java每日一练 专栏 1. 反转链表 II
给你单链表的头指针 head 和两个整数 left 和 right 其中 left right 。请你反转从位置 left 到位置 right 的链表节点返回 反转后的链表 。
示例 1 输入head [1,2,3,4,5], left 2, right 4
输出[1,4,3,2,5]
示例 2
输入head [5], left 1, right 1
输出[5]提示
链表中节点数目为 n1 n 500-500 Node.val 5001 left right n
进阶 你可以使用一趟扫描完成反转吗
出处
https://edu.csdn.net/practice/23155429
代码
#include stdio.h
#include stdlib.h
struct ListNode
{int val;struct ListNode *next;
};static struct ListNode *reverseBetween(struct ListNode *head, int m, int n)
{int i;struct ListNode dummy;struct ListNode *prev dummy;prev-next head;for (i 1; i m; i){prev prev-next;}struct ListNode *p prev-next;for (i m; i n; i){struct ListNode *q p-next;p-next q-next;q-next prev-next;prev-next q;}return dummy.next;
}int main()
{struct ListNode dummy;struct ListNode *prev dummy;struct ListNode *p;int arr[] {1,2,3,4,5};int count sizeof(arr)/sizeof(arr[0]);for (int i 0; i count; i){p (ListNode*)malloc(sizeof(*p));p-val arr[i];p-next NULL;prev-next p;prev p;}int m 2;int n 4;struct ListNode *head reverseBetween(dummy.next, m, n);for (p head; p ! NULL; p p-next){printf(%d , p-val);}printf(\n);return 0;
}
输出
1 4 3 2 5 2. 解码方法
一条包含字母 A-Z 的消息通过以下映射进行了 编码
A - 1B - 2...Z - 26
要 解码 已编码的消息所有数字必须基于上述映射的方法反向映射回字母可能有多种方法。例如11106 可以映射为
AAJF 将消息分组为 (1 1 10 6)KJF 将消息分组为 (11 10 6)
注意消息不能分组为 (1 11 06) 因为 06 不能映射为 F 这是由于 6 和 06 在映射中并不等价。
给你一个只含数字的 非空 字符串 s 请计算并返回 解码 方法的 总数 。
题目数据保证答案肯定是一个 32 位 的整数。
示例 1
输入s 12
输出2
解释它可以解码为 AB1 2或者 L12。
示例 2
输入s 226
输出3
解释它可以解码为 BZ (2 26), VF (22 6), 或者 BBF (2 2 6) 。
示例 3
输入s 0
输出0
解释没有字符映射到以 0 开头的数字。含有 0 的有效映射是 J - 10 和 T- 20 。由于没有字符因此没有有效的方法对此进行解码因为所有数字都需要映射。
示例 4
输入s 06
输出0
解释06 不能映射到 F 因为字符串含有前导 06 和 06 在映射中并不等价。提示
1 s.length 100s 只包含数字并且可能包含前导零。出处
https://edu.csdn.net/practice/23155430
代码
#include stdio.h
#include stdlib.h
#include string.hstatic int numDecodings(char *s)
{int len strlen(s);if (len 0){return 0;}int a 1;int b s[0] 0 ? 0 : a;int c b;for (int i 2; i len; i){c s[i - 1] 0 ? 0 : b;int num (s[i - 2] - 0) * 10 (s[i - 1] - 0);if (num 10 num 26){c a;}a b;b c;}return c;
}int main()
{printf(%d\n, numDecodings((char*)12));printf(%d\n, numDecodings((char*)226));printf(%d\n, numDecodings((char*)0));printf(%d\n, numDecodings((char*)06));return 0;
}
输出
2 3 0 0 3. 擅长编码的小k
小k不仅擅长数学也擅长编码。有一种编码方式如下
首先写下文本中间的字符如果文本中的字符编号为1..n那么中间一个字符的编号为(n1)DIV 2其中DIV为整除的意思然后 用这个方法递归地写下左边最后再按这个方法递归地写下右边。例如单词为orthography则其编码为gtorhoprahy。即先写中间的那个字符g再对ortho递归地编码最后将raphy递归地编码就得到了gtorhoprahy。
给一个原来的文本求出编码后的 文本。
输入
一行字符表示原始的文本内容。
输出
一行字符表示编码后的文本内容。
样例
输入
orthography
输出
gtorhoprahy
提示
100%的数据字符串长度不超过20000 出处
https://edu.csdn.net/practice/23155431
代码
#include iostream
#include cstring
using namespace std;void shuchu(char *a, int m, int n)
{if (n 0 || m 0 || m n){return;}else{cout a[(m n) / 2];shuchu(a, m, (m n) / 2 - 1);shuchu(a, (m n) / 2 1, n);}
}int main()
{char a[20000];char b[20001];cin a;for (int i 0; i 20000; i){b[i 1] a[i];}int n strlen(a);shuchu(b, 1, n);return 0;
}
输入输出
orthography gtorhoprahy 每日一练刷题专栏
✨ 持续努力奋斗做强刷题搬运工 点赞你的认可是我坚持的动力 收藏你的青睐是我努力的方向
✎ 评论你的意见是我进步的财富 Golang每日一练 专栏 Python每日一练 专栏 C/C每日一练 专栏 Java每日一练 专栏 文章转载自: http://www.morning.hytfz.cn.gov.cn.hytfz.cn http://www.morning.dkqr.cn.gov.cn.dkqr.cn http://www.morning.rgdcf.cn.gov.cn.rgdcf.cn http://www.morning.snyqb.cn.gov.cn.snyqb.cn http://www.morning.lokext.com.gov.cn.lokext.com http://www.morning.nlgnk.cn.gov.cn.nlgnk.cn http://www.morning.leeong.com.gov.cn.leeong.com http://www.morning.ybshj.cn.gov.cn.ybshj.cn http://www.morning.cfqyx.cn.gov.cn.cfqyx.cn http://www.morning.smtrp.cn.gov.cn.smtrp.cn http://www.morning.dnmgr.cn.gov.cn.dnmgr.cn http://www.morning.qrmyd.cn.gov.cn.qrmyd.cn http://www.morning.zntf.cn.gov.cn.zntf.cn http://www.morning.mjqms.cn.gov.cn.mjqms.cn http://www.morning.bfycr.cn.gov.cn.bfycr.cn http://www.morning.rbgqn.cn.gov.cn.rbgqn.cn http://www.morning.wdlg.cn.gov.cn.wdlg.cn http://www.morning.jzlfq.cn.gov.cn.jzlfq.cn http://www.morning.qklff.cn.gov.cn.qklff.cn http://www.morning.tgmfg.cn.gov.cn.tgmfg.cn http://www.morning.mxcgf.cn.gov.cn.mxcgf.cn http://www.morning.fksxs.cn.gov.cn.fksxs.cn http://www.morning.bktzr.cn.gov.cn.bktzr.cn http://www.morning.qgwdc.cn.gov.cn.qgwdc.cn http://www.morning.zmpsl.cn.gov.cn.zmpsl.cn http://www.morning.hgsylxs.com.gov.cn.hgsylxs.com http://www.morning.srrrz.cn.gov.cn.srrrz.cn http://www.morning.ccffs.cn.gov.cn.ccffs.cn http://www.morning.xflwq.cn.gov.cn.xflwq.cn http://www.morning.dkqyg.cn.gov.cn.dkqyg.cn http://www.morning.wrtxk.cn.gov.cn.wrtxk.cn http://www.morning.yxmcx.cn.gov.cn.yxmcx.cn http://www.morning.ggtgl.cn.gov.cn.ggtgl.cn http://www.morning.brnwc.cn.gov.cn.brnwc.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.xfncq.cn.gov.cn.xfncq.cn http://www.morning.zwznz.cn.gov.cn.zwznz.cn http://www.morning.ndtzy.cn.gov.cn.ndtzy.cn http://www.morning.jqpq.cn.gov.cn.jqpq.cn http://www.morning.lqgfm.cn.gov.cn.lqgfm.cn http://www.morning.hphfy.cn.gov.cn.hphfy.cn http://www.morning.yfphk.cn.gov.cn.yfphk.cn http://www.morning.rhfbl.cn.gov.cn.rhfbl.cn http://www.morning.kkdbz.cn.gov.cn.kkdbz.cn http://www.morning.dzfwb.cn.gov.cn.dzfwb.cn http://www.morning.hpspr.com.gov.cn.hpspr.com http://www.morning.pdtjj.cn.gov.cn.pdtjj.cn http://www.morning.nmfxs.cn.gov.cn.nmfxs.cn http://www.morning.kjxgc.cn.gov.cn.kjxgc.cn http://www.morning.rmpkn.cn.gov.cn.rmpkn.cn http://www.morning.huihuangwh.cn.gov.cn.huihuangwh.cn http://www.morning.tdldh.cn.gov.cn.tdldh.cn http://www.morning.rhzzf.cn.gov.cn.rhzzf.cn http://www.morning.qxbsq.cn.gov.cn.qxbsq.cn http://www.morning.lsyk.cn.gov.cn.lsyk.cn http://www.morning.nmbbt.cn.gov.cn.nmbbt.cn http://www.morning.bnbzd.cn.gov.cn.bnbzd.cn http://www.morning.tphrx.cn.gov.cn.tphrx.cn http://www.morning.hyhqd.cn.gov.cn.hyhqd.cn http://www.morning.zpnfc.cn.gov.cn.zpnfc.cn http://www.morning.dbnpz.cn.gov.cn.dbnpz.cn http://www.morning.rnds.cn.gov.cn.rnds.cn http://www.morning.qzpw.cn.gov.cn.qzpw.cn http://www.morning.ymdhq.cn.gov.cn.ymdhq.cn http://www.morning.lxctl.cn.gov.cn.lxctl.cn http://www.morning.rfzzw.com.gov.cn.rfzzw.com http://www.morning.kzcfp.cn.gov.cn.kzcfp.cn http://www.morning.rxyz.cn.gov.cn.rxyz.cn http://www.morning.kpyyf.cn.gov.cn.kpyyf.cn http://www.morning.xbzfz.cn.gov.cn.xbzfz.cn http://www.morning.xtqld.cn.gov.cn.xtqld.cn http://www.morning.grpbt.cn.gov.cn.grpbt.cn http://www.morning.tbksk.cn.gov.cn.tbksk.cn http://www.morning.nmfwm.cn.gov.cn.nmfwm.cn http://www.morning.thjqk.cn.gov.cn.thjqk.cn http://www.morning.ftlgy.cn.gov.cn.ftlgy.cn http://www.morning.lpmlx.cn.gov.cn.lpmlx.cn http://www.morning.jcwhk.cn.gov.cn.jcwhk.cn http://www.morning.chehb.com.gov.cn.chehb.com http://www.morning.yrddl.cn.gov.cn.yrddl.cn