GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add · 7256/JavaScriptNotes@f1f763b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • JS-AC
    • ac06.js
    • ac08.js
    • ac13.js
    • ac14.js
    • ac15.js
    • ac16.js
    • ac17.js
    • ac18.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎JS-AC/ac06.js‎

Copy file name to clipboard
+12-13Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
//题目6:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。
22

3-
function minNumberInRotateArray(rotateArray)
4-
{
5-
if(rotateArray.length===0){
3+
function minNumberInRotateArray(rotateArray) {
4+
if (rotateArray.length === 0) {
65
return 0;
76
}
8-
if(rotateArray.length===1){
7+
if (rotateArray.length === 1) {
98
return rotateArray[0];
10-
}
11-
var index=parseInt(Math.floor((rotateArray.length)/2));
12-
var left=rotateArray.slice(0,index);
13-
var right=rotateArray.slice(index);
9+
}
10+
var index = parseInt(Math.floor((rotateArray.length) / 2));
11+
var left = rotateArray.slice(0, index);
12+
var right = rotateArray.slice(index);
1413
var recuArray;//rotateArray[index-]>=rotateArray[0]?right:left;
15-
if(rotateArray[index-1]<rotateArray[0]){
16-
recuArray=left;
17-
}else {
14+
if (rotateArray[index - 1] < rotateArray[0]) {
15+
recuArray = left;
16+
} else {
1817
//是否还是旋转数组
19-
if(right[0]<=right[right.length-1]) return right[0];
20-
else recuArray=right;
18+
if (right[0] <= right[right.length - 1]) return right[0];
19+
else recuArray = right;
2120
}
2221
return minNumberInRotateArray(recuArray);
2322
}
Collapse file

‎JS-AC/ac08.js‎

Copy file name to clipboard
+10-11Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
//题目8:一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
22

3-
function jumpFloor(number)
4-
{
3+
function jumpFloor(number) {
54

6-
if(number == 1){
7-
return 1;
5+
if (number == 1) {
6+
return 1;
87
}
9-
if(number == 2){
10-
return 2;
8+
if (number == 2) {
9+
return 2;
1110
}
1211
n1 = 1;
1312
n2 = 2;
14-
while(number > 2){
15-
tmp = n2;
16-
n2 = n1+n2;
17-
n1 = tmp;
18-
number--;
13+
while (number > 2) {
14+
tmp = n2;
15+
n2 = n1 + n2;
16+
n1 = tmp;
17+
number--;
1918
}
2019
return n2;
2120
}
Collapse file

‎JS-AC/ac13.js‎

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//题目13:输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变。
2+
3+
function reOrderArray(array) {
4+
var odd = [];
5+
var even = [];
6+
for (var i = 0; i < array.length; i++) {
7+
if ((array[i] % 2) === 0) {
8+
even.push(array[i]);
9+
}
10+
else {
11+
odd.push(array[i]);
12+
}
13+
}
14+
return odd.concat(even);
15+
}
Collapse file

‎JS-AC/ac14.js‎

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//题目14:输入一个链表,输出该链表中倒数第k个结点。
2+
3+
function FindKthToTail(head, k) {
4+
if (!head || k <= 0) { return null; } else {
5+
var q = head;
6+
var p = head;
7+
for (var i = 0; i < k - 1; i++) {
8+
if (p.next)
9+
{ p = p.next; } else {
10+
return null;
11+
}
12+
}
13+
for (; p.next; p = p.next) {
14+
q = q.next;
15+
}
16+
return q;
17+
}
18+
}
Collapse file

‎JS-AC/ac15.js‎

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//题目15:输入一个链表,反转链表后,输出链表的所有元素。
2+
3+
function isEmptyObject(obj) {
4+
for (var name in obj) {
5+
return false;
6+
}
7+
return true;
8+
}
9+
10+
function ReverseList(pHead) {
11+
if (isEmptyObject(pHead)) {
12+
return false;
13+
}
14+
var pre = null;
15+
var next = null;
16+
while (pHead != null) {
17+
next = pHead.next;
18+
pHead.next = pre;
19+
pre = pHead;
20+
pHead = next;
21+
}
22+
return pre;
23+
}
Collapse file

‎JS-AC/ac16.js‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//题目16:输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则。
2+
3+
4+
function Merge(pHead1, pHead2) {
5+
// write code here
6+
if (pHead1 == null) {
7+
return pHead2;
8+
} else if (pHead2 == null) {
9+
return pHead1;
10+
}
11+
var result = {};
12+
if (pHead1.val < pHead2.val) {
13+
result = pHead1;
14+
result.next = Merge(pHead1.next, pHead2);
15+
} else {
16+
result = pHead2;
17+
result.next = Merge(pHead1, pHead2.next);
18+
}
19+
return result;
20+
}
Collapse file

‎JS-AC/ac17.js‎

Copy file name to clipboard
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//题目17:输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)
2+
3+
function isSubtree(root1, root2) {
4+
if (root2 == null) return true;
5+
if (root1 == null) return false;
6+
if (root1.val == root2.val) {
7+
return isSubtree(root1.left, root2.left) &&
8+
isSubtree(root1.right, root2.right);
9+
} else {
10+
return false;
11+
}
12+
}
13+
14+
function HasSubtree(pRoot1, pRoot2)
15+
{
16+
if (pRoot1 == null || pRoot2 == null) {
17+
return false;
18+
}
19+
return isSubtree(pRoot1, pRoot2) ||
20+
HasSubtree(pRoot1.left, pRoot2) ||
21+
HasSubtree(pRoot1.right, pRoot2);
22+
}
Collapse file

‎JS-AC/ac18.js‎

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//题目18:操作给定的二叉树,将其变换为源二叉树的镜像。
2+
3+
function Mirror(root)
4+
{
5+
if(root === null) {
6+
return;
7+
}
8+
var temp = root.left;
9+
root.left = root.right;
10+
root.right = temp;
11+
Mirror(root.left);
12+
Mirror(root.right);
13+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.