Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 950ad5c

Browse files
Refactor
1 parent bb55c52 commit 950ad5c

File tree

26 files changed

+22
-77
lines changed

26 files changed

+22
-77
lines changed

‎src/main/kotlin/pl/dmichalski/algorithms/_3_is_anagram/AnagramService1.kt‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ internal class AnagramService1 {
55
/**
66
* O(n log n) time complexity
77
*/
8-
fun areAnagrams(text1: String?, text2: String?): Boolean {
9-
if (text1 == null || text2 == null) {
10-
return false
11-
}
8+
fun areAnagrams(text1: String, text2: String): Boolean {
129
if (text1.isEmpty() || text2.isEmpty() || text1.length != text2.length) {
1310
return false
1411
}

‎src/main/kotlin/pl/dmichalski/algorithms/_3_is_anagram/AnagramService2.kt‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ internal class AnagramService2 {
55
/**
66
* O(n) time complexity
77
*/
8-
fun areAnagrams(text1: String?, text2: String?): Boolean {
9-
if (text1 == null || text2 == null) {
10-
return false
11-
}
8+
fun areAnagrams(text1: String, text2: String): Boolean {
129
if (text1.isEmpty() || text2.isEmpty() || text1.length != text2.length) {
1310
return false
1411
}

‎src/main/kotlin/pl/dmichalski/algorithms/_5_count_unique_values/CountUniqueValuesService.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ internal class CountUniqueValuesService {
55
/**
66
* O(n) time complexity
77
*/
8-
fun countUniqueValues(values: IntArray?): Int {
9-
if (values==null|| values.isEmpty()) {
8+
fun countUniqueValues(values: IntArray): Int {
9+
if (values.isEmpty()) {
1010
return 0
1111
}
1212
var i = 0

‎src/main/kotlin/pl/dmichalski/algorithms/_6_max_subarray_sum/MaxSubarraySumService1.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ internal class MaxSubarraySumService1 {
55
/**
66
* O(n2) time complexity
77
*/
8-
fun maxSubarraySum(values: IntArray?, numbersCountToCountSum: Int): Int? {
9-
if (values ==null||numbersCountToCountSum > values.size) {
8+
fun maxSubarraySum(values: IntArray, numbersCountToCountSum: Int): Int? {
9+
if (numbersCountToCountSum > values.size) {
1010
return null
1111
}
1212

‎src/main/kotlin/pl/dmichalski/algorithms/_6_max_subarray_sum/MaxSubarraySumService2.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ internal class MaxSubarraySumService2 {
77
/**
88
* O(n) time complexity
99
*/
10-
fun maxSubarraySum(values: IntArray?, numbersCountToCountSum: Int): Int? {
11-
if (values==null|| values.size < numbersCountToCountSum) {
10+
fun maxSubarraySum(values: IntArray, numbersCountToCountSum: Int): Int? {
11+
if (values.size < numbersCountToCountSum) {
1212
return null
1313
}
1414

‎src/main/kotlin/pl/dmichalski/algorithms/_7_binary_search/BinarySearchService.kt‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ internal class BinarySearchService {
55
/**
66
* O(log n) time complexity
77
*/
8-
fun search(sortedValues: IntArray?, numberToSearch: Int): Int {
9-
if (sortedValues == null) {
10-
return -1
11-
}
12-
8+
fun search(sortedValues: IntArray, numberToSearch: Int): Int {
139
var min = 0
1410
var max = sortedValues.size - 1
1511
while (min <= max) {

‎src/main/kotlin/pl/dmichalski/algorithms/_7_binary_search/SearchService.kt‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ internal class SearchService {
55
/**
66
* O(n) time complexity
77
*/
8-
fun search(sortedValues: IntArray?, numberToSearch: Int): Int {
9-
if (sortedValues == null) {
10-
return -1
11-
}
12-
8+
fun search(sortedValues: IntArray, numberToSearch: Int): Int {
139
for (i in sortedValues.indices) {
1410
if (sortedValues[i] == numberToSearch) {
1511
return i

‎src/main/kotlin/pl/dmichalski/algorithms/_8_naive_string_search/StringSearchService.kt‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ internal class StringSearchService {
55
/**
66
* O(n*k) time complexity
77
*/
8-
fun countNumberOfAppearances(text: String?, searchingText: String?): Int {
9-
if (text == null || searchingText == null) {
10-
return -1
11-
}
12-
8+
fun countNumberOfAppearances(text: String, searchingText: String): Int {
139
var count = 0
1410
for (i in 0 until text.length - searchingText.length + 1) {
1511
for (j in searchingText.indices) {

‎src/main/kotlin/pl/dmichalski/algorithms/_9_sorting/bubble/BubbleSortOptimizedService.kt‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ internal class BubbleSortOptimizedService {
55
/**
66
* O(n2) time complexity
77
*/
8-
fun sort(values: IntArray?): IntArray? {
9-
if (values == null) {
10-
return null
11-
}
12-
8+
fun sort(values: IntArray): IntArray? {
139
val n = values.size
1410
for (i in 0 until n - 1) {
1511
var noSwaps = true

‎src/main/kotlin/pl/dmichalski/algorithms/_9_sorting/bubble/BubbleSortService.kt‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ internal class BubbleSortService {
55
/**
66
* O(n2) time complexity
77
*/
8-
fun sort(values: IntArray?): IntArray? {
9-
if (values == null) {
10-
return null
11-
}
12-
8+
fun sort(values: IntArray): IntArray {
139
val n = values.size
1410
for (i in 0 until n - 1) {
1511
for (j in 0 until n - i - 1) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /