[Leetcode easy]存些水題
leetcode 34 最早出現和最後出現
class Solution { public int[] searchRange(int[] nums, int target) { int []ans={-1,-1} ; for(int i=0;i<nums.length;i++){ if(nums[i]==target){ ans[0]=i; break; } } for(int j=nums.length-1;j>=0;j--){if(nums[j]==target){ ans[1]=j; break; } } return ans; } }
[Leetcode easy]存些水題
相關推薦
[Leetcode easy]存些水題
public style turn pre leet leetcode class urn arch leetcode 34 最早出現和最後出現 class Solution { public int[] searchRange(int[] nums, in
leetcode easy刷題心得
持續更新 67.二進位制求和 給定兩個二進位制,返回他們的和。輸入為非空字串並且只包含1和0. class Solution { public String addBinary(String a, String b) { StringBuilder result = new
LeetCode-Easy刷題(32) Linked List Cycle
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 給定一個連結串列,確定它是否有一個迴圈
LeetCode-Easy刷題(31) Single Number
Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a li
LeetCode-Easy刷題(30) Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximu
LeetCode-Easy刷題(29) Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete
LeetCode-Easy刷題(28) Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. N
LeetCode-Easy刷題(27) Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1]
LeetCode-Easy刷題(26) Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given
LeetCode-Easy刷題(25) Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the
LeetCode-Easy刷題(24) Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this pro
LeetCode-Easy刷題(23) Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 將有序陣列轉化為二分查詢樹
LeetCode-Easy刷題(33) Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop()
leetcode 9(水題)
判斷一個整數是否是迴文數。迴文數是指正序(從左向右)和倒序(從右向左)讀都是一樣的整數。 示例 1: 輸入: 121 輸出: true 示例 2: 輸入: -121 輸出: false 解釋:
Leetcode水題——3Sum
題目 題解 這題還是比較簡單的,首先進行排序(對於沒有按下標輸出要求的題目,向考慮排序),排好序後,找第一個數,設第一個數下標為i,則第二個數從i+1開始找,因為i之前的數字的所有組合都已經找出來了,計算第一個數與第二數的和,取反,根據二分法查詢,查詢範圍為第二個數的
Leetcode水題——132模式
題目 題解 首先想到的是回溯法,但最壞演算法複雜度為O(n^3),而且題目只需要判斷是否存在,而回溯法會把所有可能都嘗試一遍,接著想到貪心,首先找到一個區域中的最小值A(下標記為i),接著從i+1開始找到一個區域內的最大值B(下標記為j),從j+1開始找,尋找位於A與
【BZOJ3781、2038】莫隊算法2水題
bsp space har 情況 ros clu while 給定 print 【BZOJ3781】小B的詢問 題意:有一個序列,包含N個1~K之間的整數。他一共有M個詢問,每個詢問給定一個區間[L..R],求Sigma(c(i)^2)的值,其中i的值從1到K,其中c(i
poj1730 - Perfect Pth Powers(完全平方數)(水題)
ostream splay -- size 技術 () isp close for /* 以前做的一道水題,再做精度控制又出了錯///。。。 */ 題目大意: 求最大完全平方數,一個數b(不超過int範圍),n=b^p,使得給定n,p最大; 題目給你一個數n,求p ; 解題
Dijkstra算法---HDU 2544 水題(模板)
fin size out hdu 2544 %d stdio.h stream 之間 sizeof /* 對於只會弗洛伊德的我,迪傑斯特拉有點不是很理解,後來發現這主要用於單源最短路,稍稍明白了點,不過還是很菜,這裏只是用了鄰接矩陣 套模板,對於鄰接表暫時還,,,沒做題,後
HDU1009_FatMouse' Trade【貪心】【水題】
clu string.h gin ins center multiple rate int which FatMouse‘ Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/