글
[LuckyAlgorithm]Intro to Tutorial Challenges (21/77)
Algorithm
2017. 12. 14. 13:23
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int searchForIndex(int[] arr,int s) {
int targetIndex = 0;
for(int j=0;j<arr.length;j++) {
if(s==arr[j]) {
targetIndex = j;
}
}
return targetIndex;
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int target = s.nextInt();
int arrayLength = s.nextInt();
int[] arr = new int[arrayLength];
for(int i=0;i<arrayLength;i++) {
arr[i] = s.nextInt();
}
System.out.println(searchForIndex(arr,target));
}
}
'Algorithm' 카테고리의 다른 글
[LuckyAlgorithm]maximizing-xor(23/77) (0) | 2018.01.03 |
---|---|
[LuckyAlgorithm]Day 26: Nested Logic(22/77) (0) | 2017.12.16 |
[LuckyAlgorithm]Alternating Characters (20/77) (0) | 2017.12.13 |
[LuckyAlgorithm]Correctness and the Loop Invariant(19/77) (0) | 2017.11.29 |
[LuckyAlgorithm]Ice Cream Parlor(18/77) (0) | 2017.11.29 |