This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static int[] removeDuplicates(int[] list) { | |
| int count = 0; | |
| for (int i = 0; i < list.length; i++) { | |
| boolean isExist = false; | |
| int value = list[i]; | |
| list[i] = 0; | |
| for (int j = 0; j < count; j++) { | |
| if (list[j] == value) { | |
| isExist = true; | |
| break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static int[] sortAndRemove(int[] list) { | |
| list = mergeSort(list); | |
| int[] temp = new int[list.length]; | |
| temp[0] = list[0]; | |
| int j = 1; | |
| for (int i = 1; i < list.length; i++) { | |
| if (list[i] != list[i - 1]) { | |
| temp[j] = list[i]; | |
| j++; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static int fib(int n) { | |
| if (n > 1) { | |
| return fib(n - 1) + fib(n - 2); | |
| } | |
| return n; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static int fact(int n) { | |
| if (n > 1) { | |
| return n * fact(n - 1); | |
| } | |
| return n; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static String reverse(String s) { | |
| int lenght = s.length(); | |
| int last = s.length() - 1; | |
| char[] temp = s.toCharArray(); | |
| for (int i = 0; i < lenght / 2; i++) { | |
| char c = temp[i]; | |
| temp[i] = temp[last - i]; | |
| temp[last - i] = c; | |
| } | |
| return new String(temp); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static String removeDuplicateChars(String s) { | |
| if (s == null) | |
| return s; | |
| int len = s.length(); | |
| if (len < 2) { | |
| return s; | |
| } | |
| char[] chars = s.toCharArray(); | |
| int index = 0; | |
| for (int i = 0; i < len; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static String removeDuplicateChars2(String s) | |
| { | |
| if (s == null) { | |
| return s; | |
| } | |
| int len = s.length(); | |
| if (len < 2){ | |
| return s; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static boolean checkIfAnagram(String s1, String s2) { | |
| int len1 = s1.length(); | |
| for (int i = 0; i < len1; i++) { | |
| if (s1.charAt(i) != s2.charAt(len1 - i - 1)) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static int getMin(int[] a) { | |
| if (a == null) { | |
| return 0; | |
| } | |
| if (a.length == 1) { | |
| return a[0]; | |
| } | |
| int min = a[0]; | |
| for (int i = 0; i < a.length; i++) { | |
| if (a[i] < min) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static int getMinValue(int[] a) { | |
| if (a == null) | |
| return -1; | |
| int lo = 0; | |
| int hi = a.length - 1; | |
| while (lo <= hi) { | |
| int mid = lo + (hi - lo) / 2; | |
| if (a[mid] > a[hi]) { | |
| lo = mid + 1; | |
| } else if (a[mid] < a[hi]) { |
OlderNewer