This file contains 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
buildRectangle(title = "MyRectangle", width = 50) |
This file contains 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
fun buildRectangle(title: String, height: Int = 100, width: Int = 100) { | |
Rectangle(title, width, height) | |
} |
This file contains 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 str1: String = null // compile time error | |
val str2: String? = null // compiles fine | |
val handler: EmailHandler? = null | |
handler.sendEmail() // compile time error | |
handler?.sendEmail() // compiles fine but doesn't call sendEmail() function |
This file contains 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
data class Person(val name: String, val age: Int) |
This file contains 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 class Person { | |
private final String name; | |
private final int age; | |
public Person(String name, int age) { | |
this.name = name; | |
this.age = age; | |
} | |
public String getName() { |
This file contains 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
fun String.lastChar() = get(length - 1) //returns the last char in a string | |
val lastChar: Char = "abcd".lastChar() // d |
This file contains 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 john1 = Person("John") | |
val john2 = Person("John") | |
john1 == john2 // true (structural equality) | |
john1 === john2 // false (referential equality) |
This file contains 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 (obj is String) { | |
print(obj.length) // x is automatically cast to String | |
} | |
if (obj !is String) { | |
print("Not a String") | |
} |
This file contains 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 i = 1 // type inferred to Int | |
val s = "abc" // type inferred to String | |
val j: Double = 1.1 // type declared explicitly |
This file contains 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
int manachersAlgorithm(String s, int N) { | |
String str = getModifiedString(s, N); | |
int len = (2 * N) + 1; | |
int[] P = new int[len]; | |
int c = 0; //stores the center of the longest palindromic substring until now | |
int r = 0; //stores the right boundary of the longest palindromic substring until now | |
int maxLen = 0; | |
for(int i = 0; i < len; i++) { | |
//get mirror index of i | |
int mirror = (2 * c) - i; |
NewerOlder