Skip to content

Commit 5eb3185

Browse files
committed
add new files
Signed-off-by: megatontech <techme@live.cn>
1 parent 96de479 commit 5eb3185

File tree

5 files changed

+172
-0
lines changed

5 files changed

+172
-0
lines changed

AddNumbers.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
type ListNode struct {
7+
Val int
8+
Next *ListNode
9+
}
10+
func scanLinklist(p *ListNode){ // 形参p是Student型的指针,指针参数需要传入一个地址
11+
for p != nil {
12+
fmt.Println(*p)
13+
p = p.Next // 这是简写,标准写法是 p = (*p).next
14+
}
15+
}
16+
//You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
17+
//
18+
//You may assume the two numbers do not contain any leading zero, except the number 0 itself.
19+
//
20+
//Example:
21+
//
22+
//Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
23+
//Output: 7 -> 0 -> 8
24+
//Explanation: 342 + 465 = 807.
25+
26+
/**
27+
* Definition for singly-linked list.
28+
* type ListNode struct {
29+
* Val int
30+
* Next *ListNode
31+
* }
32+
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
33+
Output: 7 -> 0 -> 8
34+
Explanation: 342 + 465 = 807.
35+
*/
36+
func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
37+
var l3 = ListNode{Val: 0, Next: nil}
38+
var offset,count = 0,0
39+
var lastNode = &l3
40+
for (l1!=nil||l2!=nil||offset!=0) {
41+
var temp01,temp02 = 0,0
42+
if(l1!=nil){temp01=l1.Val}
43+
if(l2!=nil){temp02=l2.Val}
44+
currNode03:=ListNode {Val: 0, Next: nil}
45+
currNode03.Val = (temp01+temp02)%10
46+
if(count==0){
47+
l3.Val = currNode03.Val
48+
l3.Next = nil
49+
lastNode = &l3
50+
}else{
51+
currNode03.Val = (currNode03.Val+offset)%10
52+
lastNode.Next = &currNode03
53+
lastNode = lastNode.Next
54+
}
55+
if((temp01+temp02+offset)>=10){
56+
offset=1
57+
}else{
58+
offset=0
59+
}
60+
count++
61+
if(l1!=nil){l1 = l1.Next}
62+
if(l2!=nil){l2 = l2.Next}
63+
}
64+
return &l3
65+
}

app.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
application: awesomeproject
2+
version: 1
3+
runtime: go114
4+
api_version: go1
5+
6+
handlers:
7+
- url: /.*
8+
script: _go_app

awesomeproject.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
arr :=[]int {3,2,4}
7+
fmt.Println(twoSum01(arr,6))
8+
var l104 = ListNode{Val: 2, Next: nil}
9+
var l103 = ListNode{Val: 3, Next: &l104}
10+
var l102 = ListNode{Val: 4, Next: &l103}
11+
var l101 = ListNode{Val: 1, Next: &l102}
12+
var l204 = ListNode{Val: 3, Next: nil}
13+
var l203 = ListNode{Val: 4, Next: &l204}
14+
var l202 = ListNode{Val: 9, Next: &l203}
15+
var l201 = ListNode{Val: 9, Next: &l202}
16+
scanLinklist(addTwoNumbers(&l101,&l201))
17+
fmt.Println(lengthOfLongestSubstring("abdwiajfwaljwalgawfegsvg"))
18+
fmt.Println(lengthOfLongestSubstring("abcabcaa"))
19+
20+
}

lengthOfLongestSubstring.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
//Longest Substring Without Repeating Characters
4+
//Medium
5+
//Given a string, find the length of the longest substring without repeating characters.
6+
//Example 1:
7+
//Input: "abcabcbb"
8+
//Output: 3
9+
//Explanation: The answer is "abc", with the length of 3.
10+
//Example 2:
11+
//Input: "bbbbb"
12+
//Output: 1
13+
//Explanation: The answer is "b", with the length of 1.
14+
//Example 3:
15+
//Input: "pwwkew"
16+
//Output: 3
17+
//Explanation: The answer is "wke", with the length of 3.
18+
//Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
19+
func lengthOfLongestSubstring(s string) int {
20+
var max = 0
21+
//var lenS = len(s)
22+
//var arr = strings.Split(s,"")
23+
//for index,cur :=range arr{
24+
// //var posi = getLatestPosi(arr[index:],arr[index])
25+
// //if(posi!=-1){
26+
// //
27+
// //}
28+
//}
29+
return max
30+
}
31+
//func getMaxSub(arr []rune , seek rune,count int) int{
32+
// var max = 0
33+
// for index,cur :=range arr{
34+
// getMaxSub(arr[])
35+
// }
36+
// return max
37+
//}
38+
//func testContains(arr []rune,seek rune) bool{
39+
// for index,cur :=range arr{
40+
// if(arr[index]==seek){
41+
// return true
42+
// }
43+
// }
44+
// return false
45+
//
46+
//}
47+
//func getLatestPosi(arr []rune,seek rune) int{
48+
// for index,cur :=range arr{
49+
// if(arr[index]==seek){
50+
// return index
51+
// }
52+
// }
53+
// return -1
54+
//}

twoSum.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
//Given an array of integers, return indices of the two numbers such that they add up to a specific target.
3+
//
4+
//You may assume that each input would have exactly one solution, and you may not use the same element twice.
5+
//
6+
//Example:
7+
//
8+
//Given nums = [2, 7, 11, 15], target = 9,
9+
//
10+
//Because nums[0] + nums[1] = 2 + 7 = 9,
11+
//return [0, 1].
12+
13+
func twoSum01(nums []int, target int) []int {
14+
var result []int = make([]int,2)
15+
for i, i2 := range nums {
16+
subnums := nums[i+1:]
17+
for j, j2 := range subnums {
18+
if(i2+j2==target){
19+
result[0]=i
20+
result[1]=j+i+1
21+
}
22+
}
23+
}
24+
return result
25+
}

0 commit comments

Comments
 (0)