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
package util | |
import ( | |
"strconv" | |
"strings" | |
) | |
func GetIpAndPortFromAddr(addr string) (ip string, port string) { | |
if strings.Contains(addr, ".") { //eg "192.0.2.1:25" | |
if ipPort := strings.Split(addr, ":"); len(ipPort) == 2 { |
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
package util | |
import "sync" | |
type SyncMap[K any, V any] struct { | |
inter *sync.Map | |
} | |
func NewSyncMap[K any, V any]() SyncMap[K, V] { | |
return SyncMap[K, V]{ |
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
package util | |
import ( | |
"fmt" | |
"strconv" | |
"strings" | |
) | |
var bitsUnits = []string{"", "K", "M", "G", "T", "P", "E", "Z"} |
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
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* 40. Combination Sum 2 | |
* Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. | |
* Each number in C may only be used once in the combination. | |
* Note: | |
* All numbers (including target) will be positive integers. | |
* The solution set must not contain duplicate combinations. |
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
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* 39. Combination Sum | |
* Given a set of candidate numbers (C) (without duplicates) and a target number (T), | |
* find all unique combinations in C where the candidate numbers sums to T. | |
* The same repeated number may be chosen from C unlimited number of times. | |
* Note: | |
* All numbers (including target) will be positive integers. |
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
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.Map; | |
import java.util.Set; | |
/** | |
* 37. Sudoku Solver | |
* Write a program to solve a Sudoku puzzle by filling the empty cells. | |
* Empty cells are indicated by the character '.'. | |
* You may assume that there will be only one unique solution. |
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
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.Map; | |
import java.util.Set; | |
/** | |
* 36. Valid Sudoku | |
* Determine if a Sudoku is valid. | |
* The Sudoku board could be partially filled, where empty cells are filled with the character '.'. | |
* A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated. |
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
/** | |
* 35. Search Insert Position | |
* Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. | |
* You may assume no duplicates in the array. | |
*/ | |
public class Solution035 { | |
public int searchInsert(int[] nums, int target) { | |
int first = 0; | |
int last = nums.length - 1; | |
if (last < 0 || target <= nums[first]) |
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
/** | |
* 34. Search for a Range | |
* Given an array of integers sorted in ascending order, find the starting and ending position of a given target value. | |
* Your algorithm's runtime complexity must be in the order of O(log n). | |
* If the target is not found in the array, return [-1, -1]. | |
*/ | |
public class Solution034 { | |
public int[] searchRange(int[] nums, int target) { | |
int first = 0; | |
int last = nums.length - 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
/** | |
* 33. Search in Rotated Sorted Array | |
* Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. | |
* (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). | |
* You are given a target value to search. If found in the array return its index, otherwise return -1. | |
* You may assume no duplicate exists in the array. | |
*/ | |
class Solution033 { | |
public int search(int[] nums, int target) { | |
int first = 0; |
NewerOlder