日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

杂乱的code

發布時間:2024/1/17 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 杂乱的code 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

/*o(n)的堆化方法*/

void myjust(vector<int>& A,int i)
{
int l=i*2+1;
int r=i*2+2;
int minn=i;
if(l<A.size()&&A[l]<A[minn])
minn=l;
if(r<A.size()&&A[r]<A[minn])
minn=r;
if(minn!=i)
{
swap(A[minn],A[i]);
myjust(A,minn);
}
}

void heapify(vector<int> &A) {
int lens=A.size();
if(lens==0) return;
for(int i=lens/2;i>=0;i--)
{
myjust(A,i);
}
}

?

求sqrt(double x)

?

?

?

鍵樹class Trie { public:struct TrieNode {bool isEnd;map<char, TrieNode*> myMap;TrieNode(){isEnd = false;}};TrieNode* root;/** Initialize your data structure here. */Trie() {root = new TrieNode();}/** Inserts a word into the trie. */void insert(string word) {TrieNode* current = root;for (int i = 0; i < word.length(); i++){if (current->myMap.find(word[i]) != current->myMap.end()){current = current->myMap[word[i]];if (i == word.length() - 1)current->isEnd = true;}else{TrieNode* tmp = new TrieNode();tmp->isEnd = (i == word.length() - 1 ? true : false);current->myMap[word[i]] = tmp;current = tmp;}}}/** Returns if the word is in the trie. */bool search(string word) {TrieNode* current = root;for (int i = 0; i < word.length(); i++){if (current->myMap.find(word[i]) != current->myMap.end()){current = current->myMap[word[i]];}else{return false;}}return current->isEnd == true ? true : false;}/** Returns if there is any word in the trie that starts with the given prefix. */bool startsWith(string prefix) {TrieNode* current = root;for (int i = 0; i < prefix.length(); i++){if (current->myMap.find(prefix[i]) != current->myMap.end()){current = current->myMap[prefix[i]];}else{return false;}}return true;} };

?

//尋找前k大小的數

int getIdx(vector<int>& nums,int left,int right) {int tmp=nums[left];while(left<right){while (left<right&&nums[right]>=tmp)right--;nums[left]=nums[right];while (left<right&&nums[left]<tmp)left++;nums[right]=nums[left];}nums[left]=tmp;return left; }vector<int> GetLeastNumbers_Solution(vector<int> input, int k) {vector<int> ans;if(input.size()<k||k<=0||input.size()==0){return ans;}int idx=-1;int left=0,right=input.size()-1;while (idx!=k-1){idx=getIdx(input,left,right);if(idx>k-1){right=idx-1;}else{left=idx+1;}}for(int i=0;i<k;i++){ans.push_back(input[i]);}return ans; }

  

  

?

轉載于:https://www.cnblogs.com/wuxiangli/p/6089937.html

總結

以上是生活随笔為你收集整理的杂乱的code的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。