Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6fe09b5

Browse files
go: 191 & 283 & 461
1 parent 3eda9c8 commit 6fe09b5

File tree

4 files changed

+123
-4
lines changed

4 files changed

+123
-4
lines changed

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ You can also ask for problem solving ideas and discuss in GitHub issues directly
6161
|167|[Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_167.java) & Python| Easy| Two-Pointer Technique
6262
|189|[Rotate Array](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_189.java) & Python| Easy| Conclusion
6363
|209|[Minimum Size Subarray Sum](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_209.java) & Python| Medium| Two-Pointer Technique
64-
|283|[Move Zeroes](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_283.java) & Python| Easy| Conclusion
64+
|283|[Move Zeroes](https://leetcode.com/problems/move-zeroes/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_283.java) & Python| Easy| Conclusion
6565
|344|[Reverse String](https://leetcode.com/problems/reverse-string/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_344.java) & Python| Easy| Two-Pointer Technique
6666
|485|[Max Consecutive Ones](https://leetcode.com/problems/diagonal-traverse/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_485.java) & Python |Easy| Two-Pointer Technique
6767
|498|[Diagonal Traverse](https://leetcode.com/problems/diagonal-traverse/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_498.java) & [Python](https://github.com/guobinhit/myleetcode/blob/master/codes/python/leetcodes/src/main/python/com/hit/basmath/learn/array_and_string/_498.py) |Medium| Introduction to 2D Array
@@ -909,7 +909,7 @@ You can also ask for problem solving ideas and discuss in GitHub issues directly
909909
|155|[Min Stack](https://leetcode.com/problems/min-stack/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/queue_stack/_155.java) & Python|Easy| Design
910910
|189|[Rotate Array](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_189.java) & Python| Easy| Array
911911
|190|[Reverse Bits](https://leetcode.com/problems/reverse-bits/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/others/_190.java) & Python |Easy| Others
912-
|191|[Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/others/_191.java) & Python |Easy| Others
912+
|191|[Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/description/)|[Java](../master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/others/_191.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/_191.go) |Easy| Others
913913
|198|[House Robber](https://leetcode.com/problems/house-robber/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/dynamic_programming/_198.java) & Python |Easy| Dynamic Programming
914914
|204|[Count Primes](https://leetcode.com/problems/count-primes/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/math/_204.java) & Python |Easy| Math
915915
|206|[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/linked_list/_206.java) & Python|Easy| Linked List
@@ -919,14 +919,14 @@ You can also ask for problem solving ideas and discuss in GitHub issues directly
919919
|242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/strings/_242.java) & Python |Easy| Strings
920920
|268|[Missing Number](https://leetcode.com/problems/missing-number/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/others/_268.java) & Python |Easy| Others
921921
|278|[First Bad Version](https://leetcode.com/problems/first-bad-version/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/binary_search/_278.java) & [Python](https://github.com/guobinhit/myleetcode/blob/master/codes/python/leetcodes/src/main/python/com/hit/basmath/learn/binary_search/_278.py)|Easy| Sorting and Searching
922-
|283|[Move Zeroes](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_283.java) & Python| Easy| Array
922+
|283|[Move Zeroes](https://leetcode.com/problems/move-zeroes/)|[Java](../master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_283.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/_283.go)| Easy| Array
923923
|326|[Power of Three](https://leetcode.com/problems/power-of-three/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/math/_326.java) & Python |Easy| Math
924924
|344|[Reverse String](https://leetcode.com/problems/reverse-string/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_344.java) & Python| Easy| Strings
925925
|350|[Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/binary_search/_350.java) & Python |Easy| Array
926926
|384|[Shuffle an Array](https://leetcode.com/problems/shuffle-an-array/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/design/_384.java) & Python |Medium| Design
927927
|387|[First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/hash_table/_387.java) & Python |Easy| Strings
928928
|412|[Fizz Buzz](https://leetcode.com/problems/fizz-buzz/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/math/_412.java) & Python |Easy| Math
929-
|461|[Hamming Distance](https://leetcode.com/problems/hamming-distance/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/others/_461.java) & Python |Easy| Others
929+
|461|[Hamming Distance](https://leetcode.com/problems/hamming-distance/description/)|[Java](../master/codes/java/leetcodes/src/main/java/com/hit/basmath/interview/top_interview_questions/easy_collection/others/_461.java) & [Go](../master/codes/go/leetcodes/interview/easy_collection/_461.go) |Easy| Others
930930

931931

932932

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package easy_collection
2+
3+
/**
4+
* 191. Number of 1 Bits
5+
* <p>
6+
* Write a function that takes an unsigned integer and return the number of '1' bits it has (also known as the Hamming weight).
7+
* <p>
8+
* Example 1:
9+
* <p>
10+
* Input: 00000000000000000000000000001011
11+
* Output: 3
12+
* Explanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits.
13+
* <p>
14+
* Example 2:
15+
* <p>
16+
* Input: 00000000000000000000000010000000
17+
* Output: 1
18+
* Explanation: The input binary string 00000000000000000000000010000000 has a total of one '1' bit.
19+
* <p>
20+
* Example 3:
21+
* <p>
22+
* Input: 11111111111111111111111111111101
23+
* Output: 31
24+
* Explanation: The input binary string 11111111111111111111111111111101 has a total of thirty one '1' bits.
25+
* <p>
26+
* <p>
27+
* Note:
28+
* <p>
29+
* Note that in some languages such as Java, there is no unsigned integer type. In this case, the input will be given as signed integer type and should not affect your implementation, as the internal binary representation of the integer is the same whether it is signed or unsigned.
30+
* In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 3 above the input represents the signed integer -3.
31+
* <p>
32+
* <p>
33+
* Follow up:
34+
* <p>
35+
* If this function is called many times, how would you optimize it?
36+
*/
37+
38+
func hammingWeight(num uint32) int {
39+
count := 0
40+
for ; num != 0; num = num & (num - 1) {
41+
count++
42+
}
43+
return count
44+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package easy_collection
2+
3+
/**
4+
* 283. Move Zeroes
5+
* <p>
6+
* Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
7+
* <p>
8+
* Example:
9+
* <p>
10+
* Input: [0,1,0,3,12]
11+
* <p>
12+
* Output: [1,3,12,0,0]
13+
* <p>
14+
* Note:
15+
* <p>
16+
* You must do this in-place without making a copy of the array.
17+
* <p>
18+
* Minimize the total number of operations.
19+
*/
20+
21+
func moveZeroes(nums []int) {
22+
if len(nums) == 0 {
23+
return nums
24+
}
25+
26+
// move non zero number
27+
nonZeroLength := 0
28+
for _, n := range nums {
29+
if n != 0 {
30+
nums[nonZeroLength] = n
31+
nonZeroLength++
32+
}
33+
}
34+
35+
// fill zero number
36+
for ; nonZeroLength < len(nums); nonZeroLength++ {
37+
nums[nonZeroLength] = 0
38+
}
39+
return nums
40+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package easy_collection
2+
3+
/**
4+
* 461. Hamming Distance
5+
* <p>
6+
* The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
7+
* <p>
8+
* Given two integers x and y, calculate the Hamming distance.
9+
* <p>
10+
* Note:
11+
* <p>
12+
* 0 ≤ x, y < 2^31.
13+
* <p>
14+
* Example:
15+
* <p>
16+
* Input: x = 1, y = 4
17+
* <p>
18+
* Output: 2
19+
* <p>
20+
* Explanation:
21+
* 1 (0 0 0 1)
22+
* 4 (0 1 0 0)
23+
* ↑ ↑
24+
* <p>
25+
* The above arrows point to positions where the corresponding bits are different.
26+
*/
27+
28+
func hammingDistance(x int, y int) int {
29+
ans := x ^ y
30+
count := 0
31+
for ; ans != 0; ans = ans & (ans - 1) {
32+
count++
33+
}
34+
return count
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /