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: | |
def preorderTraversal(self, root: TreeNode) -> List[int]: | |
# to return an empty array if root is empty | |
if not root: | |
return [] | |
# appending the root value in array and recursively going into left and right subtrees | |
return [root.val] + self.preorderTraversal(root.left) + self.preorderTraversal(root.right) |
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 TreeNode: | |
def __init__(self, val=0, left=None, right=None): | |
self.val = val | |
self.left = left | |
self.right = right | |
def initializeBinaryTree() -> TreeNode: | |
a = TreeNode(2) | |
b = TreeNode(3) |
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 PrefLocalDataSourceImpl(val context: Context) : PrefRepo { | |
override fun updateDarkMode(enabled: Boolean) { | |
val sharedPreferences = context.getSharedPreferences("darkModePref", Context.MODE_PRIVATE) | |
val editor = sharedPreferences.edit() | |
editor.putBoolean("darkMode", true) | |
editor.apply() | |
} | |
} |
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
interface PrefRepo { | |
fun updateDarkMode(enabled: Boolean) | |
} |
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 PrefViewModel(private val prefRepo: PrefRepo): ViewModel() { | |
fun updateDarkMode(enabled: Boolean) { | |
prefRepo.updateDarkMode(enabled) | |
} | |
} |
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 PrefActivity : AppCompatActivity() { | |
lateinit var viewModelFactory: PrefViewModelFactory | |
private val btnDarkMode: Button = Button(this) | |
private lateinit var viewmodel: PrefViewModel | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_pref) | |
viewModelFactory = PrefViewModelFactory((application as DIExampleApp).repository) | |
viewmodel= ViewModelProvider(this, viewModelFactory).get(PrefViewModel::class.java) | |
btnDarkMode.setOnClickListener { |
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
import android.content.Context | |
import android.os.Bundle | |
import android.widget.Button | |
import androidx.appcompat.app.AppCompatActivity | |
import com.coderefer.newyorktimesapp.R | |
class PrefActivity : AppCompatActivity() { | |
private val btnDarkMode: Button = Button(this) | |
override fun onCreate(savedInstanceState: Bundle?) { |
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.solidPrinciples.InterfaceSegregation | |
enum class TYPE { | |
FAST_FOOD, DESSERT, INDIAN, CHINESE | |
} | |
interface Food { | |
fun name(): String | |
fun type(): TYPE | |
} |
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.solidPrinciples.InterfaceSegregation | |
enum class TYPE { | |
FAST_FOOD, DESSERT, INDIAN, CHINESE | |
} | |
interface Food { | |
fun name(): String | |
fun type(): TYPE | |
fun boil() : String |
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(){} | |
} | |
open class FlyingBird : Bird() { | |
fun fly() {} | |
} | |
class Eagle : FlyingBird() | |
class Penguin : Bird() |