Skip to content

Commit 9e69e02

Browse files
author
wb-hjk570755
committed
一个数组中 连续的最大和
1 parent cbc65a3 commit 9e69e02

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.blankj.myself;
2+
3+
import com.blankj.myself.HasCycle_fast_slow_point.ListNode;
4+
5+
/**
6+
* Description:
7+
* Copyright: Copyright (c) 2012
8+
* Company: keruyun Technology(Beijing) Chengdu Co. Ltd.
9+
*
10+
* @author huangjk
11+
* @version 1.0 2020/10/3
12+
*/
13+
public class AddTwoNumbers {
14+
15+
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
16+
ListNode res = new ListNode(0);
17+
ListNode curr = res;
18+
int x,y,unit,carry=0;
19+
while (l1!=null||l2!=null){
20+
x = (l1==null?0:l1.val);
21+
y = (l2==null?0:l2.val);
22+
23+
24+
unit = (x + y + carry)%10 ;
25+
26+
curr.next = new ListNode(unit);
27+
carry = (x + y + carry)/10;
28+
29+
if(l1!=null){
30+
l1=l1.next;
31+
}
32+
33+
if(l2!=null){
34+
l2=l2.next;
35+
}
36+
37+
curr = curr.next;
38+
39+
}
40+
41+
if(carry!=0){
42+
curr.next = new ListNode(carry);
43+
}
44+
45+
return res.next;
46+
}
47+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.blankj.myself;
2+
3+
/**
4+
* Description:
5+
* Copyright: Copyright (c) 2012
6+
* Company: keruyun Technology(Beijing) Chengdu Co. Ltd.
7+
*
8+
* @author huangjk
9+
* @version 1.0 2020/10/3
10+
*/
11+
public class CountAndSay {
12+
public String countAndSay(int n) {
13+
StringBuilder res = new StringBuilder("1");
14+
for(int i=1;i<=n;i++){
15+
char[] tempArr = res.toString().toCharArray();
16+
char temp;
17+
int k=0;
18+
res = new StringBuilder();
19+
for (int j=0;j<tempArr.length;j++){
20+
if(tempArr[j]==tempArr[j+1]){
21+
k = k+1;
22+
}else {
23+
res.append(k).append(tempArr[j]);
24+
k = 0;
25+
}
26+
}
27+
}
28+
return res.toString();
29+
}
30+
}

0 commit comments

Comments
 (0)