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
//Solves the problem in O(n) time complexity | |
class Solution { | |
fun twoSum(nums: IntArray, target: Int): IntArray { | |
//initialize an empty HashMap | |
val map = hashMapOf<Int, Int>() | |
//and for every element in the array, if it exists in the Map, | |
//check if its complement exists a in the Map or not. If the complement exists then return the indices | |
//of the current element and the complement. | |
//Otherwise, put the element in the Map, and move to the next iteration. | |
for(i in 0..nums.size - 1){ |
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
/** | |
* Example: | |
* var li = ListNode(5) | |
* var v = li.`val` | |
* Definition for singly-linked list. | |
* class ListNode(var `val`: Int) { | |
* var next: ListNode? = null | |
* } | |
*/ | |
class Solution { |
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
//Finding the length of the longest substring without repeating characters | |
//Solution | |
// Iterate through an array, evaluating if new substring should be the max substring | |
//Time complexity is O(n)..since we're iterating through an array once | |
//Space complexity is constant | |
class Solution { | |
fun lengthOfLongestSubstring(str: String): Int{ | |
val map: HashMap<Char, Int> = hashMapOf() | |
var max = 0 | |
// last repeat of any character |
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
class Solution { | |
fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double { | |
// Check if num1 is smaller than num2 | |
// If not, then we will swap num1 with num2 | |
if (nums1.size > nums2.size) { | |
return findMedianSortedArrays(nums2, nums1) | |
} | |
// Lengths of two arrays | |
val m = nums1.size | |
val n = nums2.size |
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
class Solution { | |
fun reverse(x: Int): Int { | |
var res = 0 | |
var n = x | |
while (n != 0) { | |
if (Math.abs(res) > Int.MAX_VALUE/10) return 0 | |
res = res*10 + n % 10 | |
n /= 10 | |
} |
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
val builder = LatLngBounds.Builder() | |
val locBounds = LatLngBounds(LatLng(53.394655, 10.09989), LatLng(53.694865, 9.75758)) | |
builder.include(locBounds.southwest) | |
builder.include(locBounds.northeast) | |
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 100)) |
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
val regionId = MutableLiveData<Int>() | |
fun setRegionId(id: Int){ | |
regionId.value = id | |
} | |
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
<?xml version="1.0" encoding="utf-8"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |
<gradient | |
android:type="linear" | |
android:angle="45" | |
android:startColor="@color/green" | |
android:centerColor="@color/white" | |
android:endColor="@color/orange" /> | |
</shape> |
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
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
val parsedDate = LocalDateTime.parse(item.created_at, DateTimeFormatter.ISO_DATE_TIME) | |
val formattedDate = parsedDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy | HH:mm")) | |
textCreatedTime.text = formattedDate | |
} else { | |
val parser = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") | |
val formatter = SimpleDateFormat("dd.MM.yyyy | HH:mm") | |
val formattedDate = formatter.format(parser.parse(item.created_at)!!) | |
textCreatedTime.text = formattedDate | |
} |
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
// 1. The Interface | |
// --> Two ways to do it, | |
``` | |
@Multipart | |
@POST("the_endpoint") | |
suspend fun postImage( | |
@Part profile_photo: MultipartBody.Part, | |
@Part ("profile_photo") requestBody: RequestBody |