原创 Code interview:獲取數組中最小的K個數

獲取數組中最小的K個數,利用堆完成。 public class MinKNum { public void createHeap(int[]heap){ int len = heap.length;

原创 Coding interview: 二叉樹的遍歷(遞歸和非遞歸)

二叉樹的非遞歸遍歷就是使用數據結構棧來實現的,下面直接給出代碼。 前序遍歷 //遞歸 static void recursionPreIterator(Node root){ if(root == null) {

原创 Code interview: 連續數組最大和 (二維數組)

思路與這邊文章一致: https://blog.csdn.net/zhumingyuan111/article/details/80192729 因爲是二維數組可以做一個預處理,可以使得在O(1)的時間複雜度獲得到Array[

原创 Mac Grpc 環境安裝 + Demo

GOLANG安裝和配置環境變量 參考: https://blog.csdn.net/liangguangchuan/article/details/53582152 這裏沒有使用brew 進行安裝,而是選擇在官網下載安裝包進行

原创 Coding interview : 鏈表排序(選擇,插入,快排,歸併)

本文章分別給出鏈表排序的幾種方法,對於學習如何操作鏈表很有幫助。 選擇排序 public class SelectSort { //節點定義 static class Node { Node next;

原创 Coding interview :第一個沒有重複的字符

思路:兩次遍歷,第一次遍歷記錄字符出現的次數,第二次找到第一個沒有出現的字符。 代碼如下: public char firstNotRepeat(char[]str){ if(str==null || str.

原创 Coding interview:替換字符串中的空格

這裏利用一個技巧,首先統計出字符串中出現的空格數量,計算出替換之後總的數組長度,最後一定注意從後向前遍歷進行替換。 public String replaceSpace(String str,String replaceStr){

原创 Leetcode 324 Wiggle Sort II

題目描述 Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]… Example 1: Input: nu

原创 Coding interview :逆序對

結合歸併排序的原理計算逆序對數,下面給出代碼 public int inversePair(int[]array){ if(array==null || array.length <= 1) return 0;

原创 Coding Interview:打印二叉樹的邊界節點

問題描述: 給定一顆二叉樹的頭節點,按照如下規則逆時針打印邊界節點。 規則: 1.頭節點爲邊界節點 2.葉節點爲邊界節點 3.如果節點在其所在的層中是最左或者最右的,也是邊界節點。 解題思路 使用層次遍歷,如果是一層開始

原创 Leetcode : 375. Guess Number Higher or Lower II

Guess Number Higher or Lower II URL : https://leetcode.com/problems/guess-number-higher-or-lower-ii/ 解題思路: 遞歸的思路是,

原创 Leetcode: 992. Subarrays with K Different Integers

URL : https://leetcode.com/problems/subarrays-with-k-different-integers/ 思路: 該題其實代碼量不多,但是思路不好想,我是看了discuss才恍然大悟。下面給

原创 Leetcode: Longest Substring Without Repeating Characters

URL : https://leetcode.com/problems/longest-substring-without-repeating-characters/ 思路: 思路就是滑動窗口,當前字符在之前沒有出現過,則窗口左端

原创 Leetcode: 315. Count of Smaller Numbers After Self

Url : https://leetcode.com/problems/count-of-smaller-numbers-after-self/ You are given an integer array nums and you

原创 Leetcode:297. Serialize and Deserialize Binary Tree

url https://leetcode.com/problems/serialize-and-deserialize-binary-tree/ 本題使用層次遍歷就行了,下面給出代碼 /** * Definition for