Skip to content

Instantly share code, notes, and snippets.

View luojiyin1987's full-sized avatar
💭
I may be slow to respond.

luo jiyin luojiyin1987

💭
I may be slow to respond.
View GitHub Profile
@luojiyin1987
luojiyin1987 / Contains_Duplicate.go
Created August 21, 2017 04:03
Contains Duplicate
func containsDuplicate(nums []int) bool {
temp := make(map[int]int)
for _, v := range nums {
temp[v]++
if temp[v] >1 {
return true
}
}
return false
@luojiyin1987
luojiyin1987 / Longest_Palindrome.go
Last active August 21, 2017 07:11
Longest Palindrome
func longestPalindrome(s string) int {
temp := make(map[int32]int)
count := 0
var oddNumber []int
for _, v := range s {
temp[v]++
}
for _, v := range temp {
if v %2 == 0 {
@luojiyin1987
luojiyin1987 / Maximum_Product_of_Three_Numbers.go
Created August 21, 2017 07:16
Maximum Product of Three Numbers
func maximumProduct(nums []int) int {
sort.Ints(nums)
l := len(nums)
if nums[0] <0 && nums[l-1] <=0 {
return nums[l-3] * nums[l-2] * nums[l-1]
}
if nums[0]>= 0 && nums[l-1] >0 {
return nums[l-3] * nums[l-2] * nums[l-1]
}
@luojiyin1987
luojiyin1987 / Intersection_of_TwoArrays_II.go
Created August 28, 2017 13:43
Intersection of Two Arrays II
func intersect(nums1 []int, nums2 []int) []int {
temp1 := make(map[int]int)
temp2 :=make(map[int]int)
result := []int{}
for _, v := range nums1 {
temp1[v]++
}
for _, v := range nums2 {
func convertToBase7(num int) string {
if num == 0 {
return "0"
}
var positive bool
var result string
if num < 0 {
num = -num
positive = true
}
@luojiyin1987
luojiyin1987 / Student_Attendance_Record_I.go
Created August 30, 2017 15:07
Student Attendance Record I
func checkRecord(s string) bool {
countA := 0
countL := 0
for _, k := range s{
if k == 65 {
countA ++
}
if k == 76 {
countL++
@luojiyin1987
luojiyin1987 / Add_Strings.go
Last active September 5, 2017 13:47
Add Strings
func addStrings(num1 string, num2 string) string {
n1, n2 := len(num1), len(num2)
n := n1
if n < n2 {
n = n2
}
res := make([]byte, n+1, n+1)
sum := 0
for i := 0; i <= n; i++ {
if i < n1 {
//python
class Solution(object):
def findAnagrams(self, s, p):
"""
:type s: str
:type p: str
:rtype: List[int]
"""
ls, lp = len(s), len(p)
count = lp
func findAnagrams(s string, p string) []int {
ls := len(s)
lp := len(p)
count := lp
var temp []int
if ls == 0 || lp == 0 {
return temp
}
@luojiyin1987
luojiyin1987 / 报错信息.md
Last active March 24, 2018 08:43
执行 python3 manage.py migrate 报 django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')

完整报错信息

JoyLegal git:(develop) ✗ python3 manage.py  migrate
Operations to perform:
  Apply all migrations: admin, app, auth, contenttypes, easy_thumbnails, sessions, templated_email
Running migrations:
  Applying app.0037_permissionapplication...Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 101, in execute