-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.html
199 lines (183 loc) · 6.19 KB
/
a.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<h1>this is a heading</h1>
<p>这是段落</p>
<p>这又是一个段落</p>
<!-- <script>
// 两数之和
let nums = [2, 7, 11, 15], target = 9;
function a(nums, target) {
let map = {}
for (let i = 0; i < nums.length; i++) {
if (map[target - nums[i]] !== undefined) {
return [map[target - nums[i]], i]
} else {
map[nums[i]] = i
}
}
return null
}
console.log(a(nums, target))
</script> -->
<!-- <script>
// 三数之和
let nums = [-1, 0, 1, 2, -1, -1,2, -4];
var threeSum = function (nums) {
const result = [];
nums.sort((a, b) => a - b);
console.log(nums)
for (let i = 0; i < nums.length; i++) {
// 跳过重复数字
if (i && nums[i] === nums[i - 1]) {
continue;
}
let left = i + 1;
let right = nums.length - 1;
while (left < right) {
if (i === 1) {
// debugger
}
const sum = nums[i] + nums[left] + nums[right];
if (sum > 0) {
right--;
} else if (sum < 0) {
left++;
} else {
result.push([nums[i], nums[left++], nums[right--]]);
// console.log(7, result)
// // 跳过重复数字
while (nums[left] === nums[left - 1]) {
left++;
}
// 跳过重复数字
while (nums[right] === nums[right + 1]) {
right--;
}
}
}
}
return result;
}
console.log(threeSum(nums))
</script> -->
<script>
let nums = [-1, 0, 1, 2, -1, -1, 2, -4];
function getNumberSum(nums) {
// if (nums.length < 3) {
// return
// }
let result = []
nums.sort((a, b) => a - b)
for (let i = 0; i < nums.length; i++) {
if (nums[i] === nums[i - 1]) {
continue
};
let left = i + 1;
let right = nums.length - 1;
while (left < right) {
const sum = nums[i] + nums[left] + nums[right];
if (sum > 0) {
right--
} else if (sum < 0) {
left++
} else {
result.push([nums[i], nums[left++], nums[right--]]);
while (nums[left] === nums[left - 1]) {
left++
}
while (nums[right] === nums[right + 1]) {
right--
}
}
}
}
return result
}
// console.log(getNumberSum(nums));
var threeSum = function (nums) {
if (nums.length < 3) {
return []
}
let result = []
nums.sort((a, b) => a - b)
for (let i = 0; i < nums.length; i++) {
let left = i + 1
let right = nums.length - 1
if (nums[i] === nums[i - 1]) continue;
while (left < right) {
const sum = nums[i] + nums[left] + nums[right]
if (sum > 0) {
right--
} else if (sum < 0) {
left++
} else {
result.push([nums[i], nums[left++], nums[right--]])
while (nums[left] === nums[left - 1]) {
left++
}
while (nums[right] === nums[right + 1]) {
right--
}
}
}
}
return result
};
console.log(threeSum(nums));
</script>
<!-- <script>
console.log(FirstNotRepeatingChar('AAAABZXC'))
function FirstNotRepeatingChar(str) {
// write code here
// for (var i = 0; i < str.length; i++) {
console.log(str.indexOf('A'));
// if (str.indexOf(str[i]) == str.lastIndexOf(str[i])) {
// return i;
// }
// }
return -1;
}
</script> -->
<script>
// 复杂链表复制
function RandomListNode(x) {
this.val = x;
this.next = null;
this.random = null;
}
function copyRandomList(pHead) {
if (pHead === null) return;
// 对应思路二中的第一步:
var currNode = pHead;
while (currNode !== null) {
var node = new RandomListNode(currNode.val);
node.next = currNode.next;
currNode.next = node;
currNode = node.next;
}
// 对应思路二中的第二步:
currNode = pHead;
while (currNode !== null && currNode.next !== null) {
if (currNode.random) {
currNode.next.random = currNode.random.next;
}
currNode = currNode.next.next;
}
//拆分,对应思路二中的第三步:
var pCloneHead = pHead.next;
var temp = null;
currNode = pHead;
while (currNode.next !== null) {
tmp = currNode.next;
currNode.next = tmp.next;
currNode = tmp;
}
return pCloneHead;
}
</script>
</body>
</html>