mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-02 11:15:19 +08:00
Retranslate the complete Japanese online edition from Chinese (#2008)
* Retranslate the complete Japanese online edition from Chinese * Fit Japanese homepage labels and localize heading permalinks * Point Japanese contribution instructions to the Japanese preview * Replace locale conditionals with multilingual UI tables
This commit is contained in:
@@ -11,26 +11,26 @@ import utils.*;
|
||||
public class linear_search {
|
||||
/* 線形探索(配列) */
|
||||
static int linearSearchArray(int[] nums, int target) {
|
||||
// 配列を走査
|
||||
// 配列を走査する
|
||||
for (int i = 0; i < nums.length; i++) {
|
||||
// 目標要素が見つかったらそのインデックスを返す
|
||||
// 目的の要素が見つかったので、そのインデックスを返す
|
||||
if (nums[i] == target)
|
||||
return i;
|
||||
}
|
||||
// 目標要素が見つからなければ -1 を返す
|
||||
// 目的の要素が見つからなかったので、-1 を返す
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 線形探索(連結リスト) */
|
||||
static ListNode linearSearchLinkedList(ListNode head, int target) {
|
||||
// 連結リストを走査
|
||||
// 連結リストを走査する
|
||||
while (head != null) {
|
||||
// 対象ノードが見つかったら、それを返す
|
||||
// 目的のノードが見つかったので、それを返す
|
||||
if (head.val == target)
|
||||
return head;
|
||||
head = head.next;
|
||||
}
|
||||
// 対象ノードが見つからない場合は null を返す
|
||||
// 目的のノードが見つからなかったので、null を返す
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ public class linear_search {
|
||||
/* 配列で線形探索を行う */
|
||||
int[] nums = { 1, 5, 3, 2, 4, 7, 5, 9, 10, 8 };
|
||||
int index = linearSearchArray(nums, target);
|
||||
System.out.println("対象要素 3 のインデックス = " + index);
|
||||
System.out.println("目的の要素 3 のインデックス = " + index);
|
||||
|
||||
/* 連結リストで線形探索を行う */
|
||||
ListNode head = ListNode.arrToLinkedList(nums);
|
||||
ListNode node = linearSearchLinkedList(head, target);
|
||||
System.out.println("対象ノード値 3 に対応するノードオブジェクトは " + node);
|
||||
System.out.println("目的のノードの値 3 に対応するノードオブジェクトは " + node);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user