Skip to content

Instantly share code, notes, and snippets.

View charlieInDen's full-sized avatar
😈
In a den

Nishant Sharma charlieInDen

😈
In a den
View GitHub Profile
def getCount(inputStr):
num_vowels = 0
for char in inputStr:
if char in "aeiouAEIOU":
num_vowels = num_vowels + 1
return num_vowels
@charlieInDen
charlieInDen / filter_list.py
Created October 22, 2020 19:31
filter_list
def filter_list(l):
new_list =[]
for x in l:
if type(x) != str:
new_list.append(x)
return new_list
def count_bits(n):
count = 0
while n != 0 :
if n&1 :
count += 1
n = n >> 1
return count
class TicTacToe {
var rows: [Int]!
var cols: [Int]!
var diagonal: Int!
var antiDiagonal: Int!
/** Initialize your data structure here. */
init(_ n: Int) {
rows = []
class FileSystem {
class File {
var isFile = false
var files: [String: File] = [String: File]()
var content = ""
}
var root: File!
init() {
root = File()
}
class BrowserHistory {
var history: [String]!
var current: Int!
var bound: Int!
init(_ homepage: String) {
history = [homepage]
current = 0
class Solution {
var deque: [Int] = []
var nums: [Int]! = []
func cleanDeque(_ i: Int, _ k: Int) {
if deque.isEmpty == false{
if let first = deque.first, first == i - k {
deque.removeFirst()
}
}
@charlieInDen
charlieInDen / uniquePathsWithObstacles.swift
Created September 16, 2020 10:57
uniquePathsWithObstacles
class Solution {
func uniquePathsWithObstacles(_ obstacleGrid: [[Int]]) -> Int {
var grid = obstacleGrid
let row = grid.count
let col = grid[0].count
//Base case
if grid.isEmpty || grid[0][0] == 1 { return 0 }
grid[0][0] = 1
for i in 1..<row {
grid[i][0] = (grid[i][0] == 0 && grid[i-1][0] == 1) ? 1 : 0
@charlieInDen
charlieInDen / letterCombinations.swift
Created September 16, 2020 10:39
letterCombinations
class Solution {
var hashMap: [String: String] = ["2": "abc", "3": "def", "4": "ghi", "5": "jkl", "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz"]
func generateCombination(result: String, nextDigit: String, output: inout [String]) {
if nextDigit.isEmpty {
output.append(result)
return
}else {
var newDigit = nextDigit
let firstString = newDigit.removeFirst()
if let value = hashMap[String(firstString)] {
let evenNumbers = [2,4,6,8,10]
let half = evenNumbers.map { $0/2 }
//[1, 2, 3, 4, 5]