easy
betty1121
这个作者很懒,什么都没留下…
展开
-
548. Bounded Random Number
Write a function that returns a random number within the range of [a, b] with equal probabilities.Note: you can use Java’s Random class.class Solution { public int random(int a, int b) { Random rand = new Random(); int i = a + rand.ne原创 2021-06-26 07:11:39 · 169 阅读 · 0 评论 -
552. Sum of Numbers in a Stack
Calculate the sum of all numbers in a Stack.Assumption: The Stack is not null or empty.Example:Stack contains 7,5,3,0Answer: 15class Solution { public int sumOfStack(Deque<Integer> stack) { int sum = stack.pop(); while (!s原创 2021-06-26 07:07:56 · 167 阅读 · 0 评论 -
551. Maximum Number in a Queue
Given a queue of integers, find the maximum number in it.Assumption: the queue is not null or empty.Example:Queue contains 5,8,3,2,7Answer: 8.class Solution { public int maxInQueue(Queue<Integer> queue) { int max = queue.poll();原创 2021-06-26 07:03:00 · 101 阅读 · 0 评论 -
9. Palindrome Number
Given an integerx, returntrueifxis palindrome integer.An integer is apalindromewhen it reads the same backward as forward. For example,121is palindrome while123is not.Example 1:Input: x = 121Output: trueExample 2:Input: x = -121...原创 2021-03-12 19:39:15 · 92 阅读 · 0 评论 -
13. Roman to Integer
Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D 500M 1000For example,2is written asI...原创 2021-03-12 19:34:13 · 92 阅读 · 0 评论 -
1527. Patients With a Condition----字母选择 like %...%
Table:Patients+--------------+---------+| Column Name | Type |+--------------+---------+| patient_id | int || patient_name | varchar || conditions | varchar |+--------------+---------+patient_id is the primary key for this table.'co.原创 2020-09-30 07:22:03 · 318 阅读 · 0 评论 -
1543. Fix Product Name Format----去掉字符串空格trim()
Table:Sales+--------------+---------+| Column Name | Type |+--------------+---------+| sale_id | int || product_name | varchar || sale_date | date |+--------------+---------+sale_id is the primary key for this table.Each row .原创 2020-09-30 02:44:51 · 158 阅读 · 0 评论 -
1435. Create a Session Bar Chart----case when
Table:Sessions+---------------------+---------+| Column Name | Type |+---------------------+---------+| session_id | int || duration | int |+---------------------+---------+session_id is the primary key for .原创 2020-09-26 08:56:32 · 635 阅读 · 0 评论 -
586. Customer Placing the Largest Number of Orders
思路:原题只有exactly one 最大订单数量,group by之后用订单量降序排列,并limit取第一个值如果不止一个最大订单数,找出最大订单值,然后找出订单量等于这个值的就可以了。Query thecustomer_numberfrom theorderstable for the customer who has placed the largest number of orde...原创 2018-04-17 07:07:13 · 797 阅读 · 0 评论 -
1050. Actors and Directors Who Cooperated At Least Three Times----count() 可以放在having后面
Table:ActorDirector+-------------+---------+| Column Name | Type |+-------------+---------+| actor_id | int || director_id | int || timestamp | int |+-------------+---------+timestamp is the primary key column for this table..原创 2020-09-24 13:11:55 · 346 阅读 · 0 评论 -
597. Friend Requests I: Overall Acceptance Rate(必看)----计算一对字段出现的次数
Round() and isnull, round() can be used directly.In social network like Facebook or Twitter, people send friend requests and accept others’ requests as well. Now given two tables as below:Table:frie...原创 2018-04-19 08:02:25 · 2770 阅读 · 0 评论 -
1084. Sales Analysis III----not between
Table:Product+--------------+---------+| Column Name | Type |+--------------+---------+| product_id | int || product_name | varchar || unit_price | int |+--------------+---------+product_id is the primary key of this table.Tab.原创 2020-09-23 15:35:19 · 132 阅读 · 0 评论 -
53. Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".class Solution: """ @param: s: A string @return: A string """ ...原创 2018-07-12 16:07:40 · 127 阅读 · 0 评论 -
415. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Example"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome.Ch...原创 2018-07-12 16:09:57 · 179 阅读 · 0 评论 -
521. Remove Duplicate Numbers in Array
Given an array of integers, remove the duplicate numbers in it.You should:Do it in place in the array.Move the unique numbers to the front of the array.Return the total number of the unique numbers.Ex...原创 2018-07-12 16:19:23 · 155 阅读 · 0 评论 -
483. Convert Linked List to Array List
Convert a linked list to an array list.ExampleGiven 1->2->3->null, return [1,2,3]class Solution: """ @param head: the head of linked list. @return: An integer list """ def...原创 2018-07-12 16:29:12 · 190 阅读 · 0 评论 -
225. Find Node in Linked List
Find a node with given value in a linked list. Return null if not exists.ExampleGiven 1->2->3 and value = 3, return the last node.Given 1->2->3 and value = 4, return null.class Solution: ...原创 2018-07-12 17:25:05 · 240 阅读 · 0 评论 -
219. Insert Node in Sorted Linked List
Insert a node in a sorted linked list.ExampleGiven list = 1->4->6->8 and val = 5.Return 1->4->5->6->8.class Solution: """ @param head: The head of linked list. @param ...原创 2018-07-13 08:15:51 · 384 阅读 · 0 评论 -
495. Implement Stack
495. Implement StackImplement a stack. You can use any data structure inside a stack except stack itself to implement it.class Stack: """ @param: x: An integer @return: nothing """ ...原创 2018-07-13 09:22:55 · 168 阅读 · 0 评论 -
leetcode: 20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid bu...原创 2018-02-03 00:46:12 · 112 阅读 · 0 评论 -
172. Remove Element
172. Remove ElementGiven an array and a value, remove all occurrences of that value in place and return the new length.The order of elements can be changed, and the elements after the new length don't...原创 2018-07-12 16:06:07 · 156 阅读 · 0 评论