Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-kotlin.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-csharp.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-javascript.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-typescript.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-python.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify-copy-code@2.1.1/dist/docsify-copy-code.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script>
Expand Down
19 changes: 19 additions & 0 deletions lcof/面试题03. 数组中重复的数字/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,25 @@ public:
};
```

### **TypeScript**

```ts
function findRepeatNumber(nums: number[]): number {
let n: number = nums.length;
for (let i: number = 0; i < n; i++) {
while (nums[i] != i) {
if (nums[i] == nums[nums[i]]) return nums[i];
swap(nums, i, nums[i]);
}
}
return -1;
};

function swap (nums: number[], i: number, j: number): void {
[nums[i], nums[j]] = [nums[j], nums[i]];
}
```

### **...**

```
Expand Down
14 changes: 14 additions & 0 deletions lcof/面试题03. 数组中重复的数字/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function findRepeatNumber(nums: number[]): number {
let n: number = nums.length;
for (let i: number = 0; i < n; i++) {
while (nums[i] != i) {
if (nums[i] == nums[nums[i]]) return nums[i];
swap(nums, i, nums[i]);
}
}
return -1;
};

function swap (nums: number[], i: number, j: number): void {
[nums[i], nums[j]] = [nums[j], nums[i]];
}