Skip to content

Instantly share code, notes, and snippets.

@idhowardgj94
Created June 27, 2020 10:29
Show Gist options
  • Save idhowardgj94/5fa780bb9a706629736cefef867fb561 to your computer and use it in GitHub Desktop.
Save idhowardgj94/5fa780bb9a706629736cefef867fb561 to your computer and use it in GitHub Desktop.
haskell
runningSum :: [ Int ] -> Maybe [ Int ]
runningSum x = Just (sum' x a)
    where a = 0; sum' [] a =  []
          sum' (x:xs) a = (a+x) : sum' xs (a+x)

main = do
    putStrLn "1480. Running Sum of 1d Array"
    putStrLn "https://leetcode.com/problems/running-sum-of-1d-array/"
@idhowardgj94
Copy link
Author

import Data.Bits

xorOperation :: Int -> Int -> Int
xorOperation n start = 
  let nums = [start + 2 * i | i <-[0 .. (n - 1)] ]
  in foldl xor 0 nums 

main = do
  print "question from https://leetcode.com/problems/xor-operation-in-an-array/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment