随笔分类 -  LeetCode

摘要:题目: Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal. Example 1: Example 2: Note: 0 < s1.length, s2 阅读全文
posted @ 2018-02-15 13:50 Sindyang 阅读(128) 评论(0) 推荐(0)
摘要:题目: Given a binary tree, return the preorder traversal of its nodes' values. 思路: 二叉树的前序遍历一般分为递归和非递归两种,非递归通过栈来存储节点。 代码: 递归: 循环: 阅读全文
posted @ 2018-01-14 23:17 Sindyang 阅读(105) 评论(0) 推荐(0)
摘要:题目: Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 思路: 这道题看起来并不难,但是有很多需要注意的点,我用了很久的时间才通过这道题。大致的思路 阅读全文
posted @ 2018-01-14 20:27 Sindyang 阅读(146) 评论(0) 推荐(0)
摘要:题目: 448. Find All Numbers Disappeared in an Array Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot 阅读全文
posted @ 2018-01-13 20:03 Sindyang 阅读(161) 评论(0) 推荐(0)
摘要:题目: 1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each inpu 阅读全文
posted @ 2017-07-18 23:42 Sindyang 阅读(193) 评论(0) 推荐(0)
摘要:题目: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example:Given n = 2, return 91. (The answer should be 阅读全文
posted @ 2017-06-11 11:08 Sindyang 阅读(152) 评论(0) 推荐(0)
摘要:题目: Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4. However, you can add 阅读全文
posted @ 2017-06-04 14:53 Sindyang 阅读(220) 评论(0) 推荐(0)
摘要:题目: Sort a linked list using insertion sort. 思路: 链表的插入排序和数组的插入排序略有不同。以链表4->2->3->1->5为例,为方便操作添加一个头节点-1,此时链表为-1->4->2->3->1->5。基本思路为一次选择前后两个节点,若后节点大于前节 阅读全文
posted @ 2017-06-02 21:33 Sindyang 阅读(139) 评论(0) 推荐(0)
摘要:题目: 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. Yo 阅读全文
posted @ 2017-06-02 21:17 Sindyang 阅读(159) 评论(0) 推荐(0)
摘要:题目: 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]. Note: You may a 阅读全文
posted @ 2017-06-02 15:35 Sindyang 阅读(139) 评论(0) 推荐(0)
摘要:题目: Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin t 阅读全文
posted @ 2017-05-09 10:30 Sindyang 阅读(183) 评论(0) 推荐(0)
摘要:题目: Reverse a singly linked list. 思路: 以1—>2->3->4为例,链表反转的过程如下: 第一次循环结束: head: 2->3->4->NULL newhead: 1->NULL 第二次循环结束: head: 3->4->NULL newhead: 2->1-> 阅读全文
posted @ 2017-05-04 13:04 Sindyang 阅读(131) 评论(0) 推荐(0)
摘要:题目: 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 -> 阅读全文
posted @ 2017-05-04 10:49 Sindyang 阅读(102) 评论(0) 推荐(0)
摘要:题目: Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exi 阅读全文
posted @ 2017-04-27 20:41 Sindyang 阅读(117) 评论(0) 推荐(0)
摘要:题目: 141.Given a linked list, determine if it has a cycle in it. 142.Given a linked list, return the node where the cycle begins. If there is no cycle, 阅读全文
posted @ 2017-04-23 11:58 Sindyang 阅读(196) 评论(0) 推荐(0)
摘要:题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is l 阅读全文
posted @ 2017-03-19 17:40 Sindyang 阅读(188) 评论(0) 推荐(0)
摘要:题目: Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums exc 阅读全文
posted @ 2017-03-11 17:15 Sindyang 阅读(178) 评论(0) 推荐(0)
摘要:题目: Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would hav 阅读全文
posted @ 2017-02-18 18:55 Sindyang 阅读(176) 评论(0) 推荐(0)
摘要:题目: 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 i 阅读全文
posted @ 2017-02-17 23:42 Sindyang 阅读(139) 评论(0) 推荐(0)