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
func numRabbits(answers []int) int { | |
if len(answers) == 0 { | |
return 0 | |
} | |
cnt := make(map[int]int) | |
sum := 0 | |
for _, n := range answers { | |
cnt[n]++ |
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
func topKFrequent(nums []int, k int) []int { | |
cnt := make(map[int]int) | |
idx := make(map[int]int) | |
res := []int{} | |
for _, x := range nums { | |
cnt[x]++ | |
if cnt[x] != 1 { | |
moveTo := -1 | |
for i:=idx[x]-1; i>=0; i-- { |
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
func uniquePathsWithObstacles(obstacleGrid [][]int) int { | |
if obstacleGrid[0][0] == 1 || obstacleGrid == nil { | |
return 0 | |
} | |
obstacleGrid[0][0] = 1 | |
maxX := len(obstacleGrid[0]) | |
maxY := len(obstacleGrid) | |
for i:=1; i<maxY; i++ { |
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
func asteroidCollision(asteroids []int) []int { | |
if len(asteroids) <= 1 { | |
return asteroids | |
} | |
last := []int{asteroids[0]} | |
for _, ast := range asteroids[1:] { | |
for { | |
if len(last) == 0 { | |
last = append(last, ast) |
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
/** | |
* Definition for a binary tree node. | |
* type TreeNode struct { | |
* Val int | |
* Left *TreeNode | |
* Right *TreeNode | |
* } | |
*/ | |
func searchTree(node *TreeNode, sum int, target int) [][]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
// a[2] == 0, the zero value of the int 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
var a [4]int | |
a[0] = 1 | |
i := a[0] | |
// i == 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
// Objective-C , iOS 8 이상 | |
TestViewController* vc = [[TestViewController alloc] init]; | |
vc.providesPresentationContextTransitionStyle = YES; | |
vc.definesPresentationContext = YES; | |
[vc setModalPresentationStyle:UIModalPresentationOverCurrentContext]; | |
[self.navigationController presentViewController:vc animated:NOcompletion:nil]; |
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
public class SomePublicClass { // explicitly public class | |
public var somePublicProperty = 0 // explicitly public class member | |
var someInternalProperty = 0 // implicitly internal class member | |
fileprivate func someFilePrivateMethod() {} // explicitly file-private class member | |
private func somePrivateMethod() {} // explicitly private class member | |
} | |
class SomeInternalClass { // implicitly internal class | |
var someInternalProperty = 0 // implicitly internal class member | |
fileprivate func someFilePrivateMethod() {} // explicitly file-private class member |
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 SomeInternalClass {} // implicitly internal | |
let someInternalConstant = 0 // implicitly internal |