# ARTS Week 21(ARTS Week 21)-其他

## ARTS Week 21(ARTS Week 21)

### Algorithm

``nums``

``nums``
``k``
``0 <= k < nums.length``
``[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]``
``[0,1,2,4,5,6,7]``
``[4,5,6,7,0,1,2]``

``nums``
``target``
``nums``
``target``
``-1``
``````输入：nums = [4,5,6,7,0,1,2], target = 0

``````
``````class Solution {
public int search(int[] nums, int target) {
if (nums.length == 1) {
if (nums[0] == target) {
return 0;
} else {
return -1;
}
}

int left = 0;
int right = nums.length - 1;
int ans = -1;
while (left < right) {
if (nums[left] == target) {
ans = left;
break;
}
if (nums[right] == target) {
ans = right;
break;
}

int mid = left + (right - left) / 2;
if (nums[mid] == target) {
ans = mid;
break;
}

if (nums[mid] >= nums[0]) { // nums[0], NOT nums[mid]
if (target >= nums[0] && target < nums[mid]) {
right = mid - 1;
} else {
left = mid + 1;
}
} else {
if (target > nums[mid] && target < nums[right]) {
left = mid + 1;
} else {
right = mid - 1;
}
}
}
return ans;
}
}
``````

### Review

• Anki：Anki 是一个免费的开源抽认卡程序，你可以利用它来帮你记住任何东西。
• Dextroamphetamine：是一种可以增强认知的兴奋剂
• R：R语言可以有效地组织和可视化数据
• sci-hub 和 Kindle、Z-Library、Calibre：sci-hub 可以免费获取到很多科学论文；Kindle 是阅读工具，你可以在 Z-Library 上找到很多想要的书，再通过 Calibre 来将这些书导入到 Kindle 中
• 保持良好的开放判断：你可以通过购买、阅读大量书籍，来使得你更加理性并减少偏见认知的影响。

### Tip

``printf``
``stdout``
``fflush``
``printf``
``````// Method 1:
printf("Starting nets allocation...");
fflush(stdout);

// Method 2:
printf("Starting nets allocation...\n");
``````

### Share

``Anki``
————————

### Algorithm

This week’s leetcode topic is 33 Search rotation sort array

Integer arrays are arranged in ascending order. The values in the array are < strong > different from each other < / strong >.

``nums``

Before passing to the function, the < strong > rotation < / strong > is performed on a previously unknown subscript (), so that the array becomes (subscript counts from 0). For example, after rotation at subscript 3, it may become.

``nums``
``k``
``0 <= k < nums.length``
``[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]``
``[0,1,2,4,5,6,7]``
``[4,5,6,7,0,1,2]``

Give you the array and an integer of < / strong > after < strong > rotation. If the target value exists in, return its subscript, otherwise return it.

``nums``
``target``
``nums``
``target``
``-1``
``````输入：nums = [4,5,6,7,0,1,2], target = 0

``````
``````class Solution {
public int search(int[] nums, int target) {
if (nums.length == 1) {
if (nums[0] == target) {
return 0;
} else {
return -1;
}
}

int left = 0;
int right = nums.length - 1;
int ans = -1;
while (left < right) {
if (nums[left] == target) {
ans = left;
break;
}
if (nums[right] == target) {
ans = right;
break;
}

int mid = left + (right - left) / 2;
if (nums[mid] == target) {
ans = mid;
break;
}

if (nums[mid] >= nums[0]) { // nums[0], NOT nums[mid]
if (target >= nums[0] && target < nums[mid]) {
right = mid - 1;
} else {
left = mid + 1;
}
} else {
if (target > nums[mid] && target < nums[right]) {
left = mid + 1;
} else {
right = mid - 1;
}
}
}
return ans;
}
}
``````

### Review

The English article in this week’s review is: I hope I know something earlier

In this paper, the author introduces some commonly used software and tools. The following is a detailed introduction:

• Anki: anki is a free open source flashcard program that you can use to help you remember anything.
• Dextroamphetamine：是一种可以增强认知的兴奋剂
• R: R language can effectively organize and visualize data
• sci-hub 和 Kindle、Z-Library、Calibre：sci-hub 可以免费获取到很多科学论文；Kindle 是阅读工具，你可以在 Z-Library 上找到很多想要的书，再通过 Calibre 来将这些书导入到 Kindle 中
• Maintain good open judgment: you can make you more rational and reduce the impact of biased cognition by buying and reading a large number of books.

### Tip

Why is it not output in time after the call? Because the output stream is buffered by default, if you want to output immediately, you need to brush a new stream (use) or print line breaks in:

``printf``
``stdout``
``fflush``
``printf``
``````// Method 1:
printf("Starting nets allocation...");
fflush(stdout);

// Method 2:
printf("Starting nets allocation...\n");
``````

### Share

After reading the introduction in the review above, I intend to try this software.

``Anki``