Leetcode
文章平均质量分 67
sophia_tone2w
这个作者很懒,什么都没留下…
展开
-
Leetcode--No.268--Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm shoul原创 2016-06-03 22:54:48 · 249 阅读 · 0 评论 -
LeetCode--No.268--Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.public class Solution {原创 2016-06-03 23:58:24 · 267 阅读 · 0 评论 -
LeetCode--No.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.原创 2016-06-04 00:06:36 · 276 阅读 · 0 评论 -
LeetCode--No.19--Remove Nth Node From End Of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2016-06-06 01:11:22 · 265 阅读 · 0 评论 -
LeetCode--No.253--Meeting Rooms II
Given an array of meeting time intervals consisting of start and end times[[s1,e1],[s2,e2],...](si< ei), find the minimum number of conference rooms required.Example 1:Input: [[0, 30],[5, 1...原创 2019-05-08 20:32:05 · 142 阅读 · 0 评论 -
LeetCode--No.46--Permutations
Given a collection ofdistinctintegers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]绝对是经典题啊还记得当初在cts的办公...原创 2019-05-13 20:48:21 · 113 阅读 · 0 评论 -
LeetCode--No.138--Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return adeep copyof the list.Example 1:Input:{"$id":"1...原创 2019-05-09 10:52:25 · 94 阅读 · 0 评论 -
LeetCode--No.49--Group Anagrams
我今天太累了,累到刷不动。这道题抄的。有几个常用的function, 但是我不是很记得清楚的1. char[] ca = s.toCharArray()2. String aaa = String.valueOf(ch)3. return new ArrayList(ans.values());这样就不用再循环一遍重新加一次,一行代码就能搞定,一定要记住啊class Sol...原创 2019-05-14 09:20:58 · 104 阅读 · 0 评论 -
LeetCode--No.11--Container With Most Water
Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two...原创 2019-05-09 11:23:19 · 248 阅读 · 0 评论 -
LeetCode--No.3--Longest Substring Without Repeating Characters
Given a string, find the length of thelongest substringwithout repeating characters.Example 1:Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2:...原创 2019-05-06 20:03:32 · 106 阅读 · 0 评论 -
LeetCode--No.973--K Closest Points to Origin
We have a list ofpointson the plane. Find theKclosest points to the origin(0, 0).(Here, the distance between two points on a plane is the Euclidean distance.)You may return the answer in any...原创 2019-05-06 20:39:57 · 127 阅读 · 0 评论 -
LeetCode--No.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 ...原创 2019-05-10 10:08:57 · 77 阅读 · 0 评论 -
LeetCode--No.15--3Sum
早上睡醒了不能玩手机啊,晚上睡觉的时候手机还是要放得远一点。抄了一道3sum. 有机会复习一下吧。感觉以后即使用最笨的方法,也要写出来跑一下才可以。要复习一下不同数据结构之间的转换,晚上总结一下。class Solution { public List<List<Integer>> threeSum(int[] nums) { List...原创 2019-05-07 20:42:16 · 59 阅读 · 0 评论 -
LeetCode--No.322--Coin Change
322.Coin ChangeMedium166272FavoriteShareYou are given coins of different denominations and a total amount of moneyamount. Write a function to compute the fewest number of coins that you need t...原创 2019-05-12 10:18:00 · 136 阅读 · 0 评论 -
LeetCode--No.1041--Robert Bounded in Circle
On an infinite plane, arobot initially stands at(0, 0)and faces north.The robot can receive one of three instructions:"G": go straight 1 unit; "L": turn 90 degrees to the left; "R": turn 90 d...原创 2019-05-12 12:23:25 · 79 阅读 · 0 评论 -
LeetCode--No.22--Generate Parentheses
Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())"...原创 2019-05-12 23:41:37 · 117 阅读 · 0 评论 -
LeetCode--No.31--Next Permutation
Implementnext permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible o...原创 2019-05-13 06:48:00 · 92 阅读 · 0 评论 -
LeetCode--No.771-Jewels and Stones
虽然是很简单的题,但是发现一个问题。就是如何遍历一个String更好一点class Solution { public int numJewelsInStones(String J, String S) { if (J == null || S == null) return 0; Set<Character> set = n...原创 2019-05-13 07:02:28 · 92 阅读 · 0 评论 -
LeetCode--NO.169--Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2016-06-03 23:49:41 · 256 阅读 · 0 评论 -
LeetCode--No.160--Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2016-06-05 23:47:20 · 229 阅读 · 0 评论 -
LeetCode--No.142--Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.(这道题做错了太多遍,又没有test cases,实在蛋疼。)自己之前的想法一直是错误的。直到上网查了其他人的算法,才明白,惭原创 2016-06-05 22:40:56 · 243 阅读 · 0 评论 -
LeetCode--No.217--Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element转载 2016-06-04 00:17:29 · 224 阅读 · 0 评论 -
LeetCode--No.53--Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1]原创 2016-06-04 04:03:50 · 262 阅读 · 0 评论 -
LeetCode--No.237--Delete Node In a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2016-06-04 04:28:48 · 396 阅读 · 0 评论 -
LeetCode--No.136--Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2016-06-08 22:18:22 · 224 阅读 · 0 评论 -
LeetCode--No.349--Intersection of Two Arrays2
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.T原创 2016-06-09 00:08:02 · 305 阅读 · 0 评论 -
LeetCode--No.242--Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may ass原创 2016-06-09 00:38:43 · 219 阅读 · 0 评论 -
网络流入门
部分转自:http://www.cnblogs.com/ZJUT-jiangnan/p/3632525.html转载:网络流基础篇——Edmond-Karp算法 BY纳米黑客网络流的相关定义:源点:有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点。汇点:另一个点也很特殊,只进不出,叫做汇点。容量和流量:每条有向边上有两个量,容量和流量,转载 2016-06-09 06:25:28 · 331 阅读 · 0 评论 -
LeetCode--No.206--Reverse Linked List
Reverse a singly linked list.思路:链表中节点 1-->2-->3-->4-->5-->6...-->n将节点设置为prev-->head-->next让head指向prev: prevnext而后将prev与head平移: prev/** * Definition for singly-linked list. * public class原创 2016-06-05 03:01:31 · 235 阅读 · 0 评论 -
LeetCode--No.328--Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in原创 2016-06-05 04:53:07 · 229 阅读 · 0 评论 -
LeetCode--No.83--Remove Duplicates From Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** * Definition f原创 2016-06-05 05:07:58 · 238 阅读 · 0 评论 -
LeetCode--No.141--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?以下是正确的解法/** * Definition for singly-linked list. * class ListNode { * int原创 2016-06-05 05:24:49 · 178 阅读 · 0 评论 -
LeetCode--No.21--Merge Two Sorted List
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists这个是我写的第一版,但是超时了。/** * Definition for singly-linked原创 2016-06-05 06:37:43 · 191 阅读 · 0 评论 -
LeetCode--No.24--Swap Nodes In Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2016-06-05 07:08:55 · 210 阅读 · 0 评论 -
LeetCode--No.347--Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].我的代码思路:1. 首先建立map,扫描nums数组,数组值作为key,该值出现频率作为value。2. 对于该map原创 2016-06-12 03:43:27 · 254 阅读 · 0 评论 -
LeetCode--No.347--Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].思路:1. 新建map,将nums中的数据整理放入其中。key为nums值,value为该值出现频率。2. 想办法原创 2016-06-12 03:50:37 · 175 阅读 · 0 评论 -
LeetCode--No.350--Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as ma原创 2016-06-12 04:43:12 · 238 阅读 · 0 评论 -
LeetCode--No.202--Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares原创 2016-06-12 05:10:34 · 205 阅读 · 0 评论 -
LeetCode--No.560--Subarray Sum Equals K
Given an array of integers and an integerk, you need to find the total number of continuous subarrays whose sum equals tok.Example 1:Input:nums = [1,1,1], k = 2Output: 2Note:The length...原创 2019-05-13 08:11:15 · 103 阅读 · 0 评论