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
open class Bird{ | |
fun makeSound(){} | |
fun fly() {} | |
} | |
class Eagle : Bird() | |
class Penguin : Bird() // fails LSP because it cannot fly therefore has different behaviour and cannot call fly() method |
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
package main.leetcode.kotlin | |
class Mariott { | |
private val basePrice = 2000 | |
private val tax = 500 | |
fun getPrice(): Int { | |
return basePrice + tax | |
} | |
} | |
class Taj { |
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
package main.leetcode.kotlin | |
interface Hotel { | |
fun getPrice(): Int | |
} | |
class Mariott : Hotel { | |
private val basePrice = 2000 | |
private val tax = 500 | |
override fun getPrice(): Int { |
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
override fun onBindViewHolder(postsViewHolder : ViewHolder, position: Int) { | |
val post = posts[position] | |
holder.title!!.text = post.title | |
holder.description!!.text = post.description | |
holder.hashtags.text = AppUtils.convertListToStr(post.hashTags) | |
} |
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
override fun onBindViewHolder(postsViewHolder : ViewHolder, position: Int) { | |
val post = posts[position] | |
holder.title!!.text = post.title | |
holder.description!!.text = post.description | |
var hashtags = post.hashTags | |
val sb = StringBuilder() | |
hashtags.forEach { | |
sb.apply { | |
append(it) | |
append(",") |
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
# find next greater node and print it | |
# eg: | |
# Input: [2,1,5] | |
# Output: [5,5,0] | |
# Definition for singly-linked list. | |
from typing import List | |
# Definition for singly-linked list. |
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 Node: | |
def __init__(self, data=None): | |
self.data = data | |
self.next = None | |
""" | |
Deleting a node at start. | |
""" | |
def delete_at_start(head): |
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
def delete_at_pos(head, position): | |
if not head: | |
return None | |
if position is 0: | |
return head.next | |
prev_node = head | |
curr_node = head.next | |
current_pos = 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
def delete_at_end(head): | |
if not head: | |
return None | |
prev_node = head | |
while prev_node.next.next: | |
prev_node = prev_node.next | |
prev_node.next = None | |
return head |
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
def delete_at_start(head): | |
# edge case: return if head is null | |
if not head: | |
return None | |
head = head.next # moving head to next node | |
return head |