Description Implement an algorithm to determine if a string has all unique characters. Example Given "abc", return true. Given "aab", return false. Challenge What if you can not use additional data structures? 解题:题目要求判断字符串是否有重复的元素,并且要求…
Description Given a collection of intervals, merge all overlapping intervals. Example Given intervals => merged intervals: [ [ (1, 3), (1, 6), (2, 6), => (8, 10), (8, 10), (15, 18) (15, 18) ] ] Challenge O(n log n) time and O(1) extra space. 题意:给定一个…
Description Write a method to replace all spaces in a string with %20. The string is given in a characters array, you can assume it has enough space for replacement and you are given the true length of the string. You code should also return the new…
Description Write a method anagram(s,t) to decide if two strings are anagrams or not. Clarification What is Anagram? Two strings are anagram if they can be the same after change the order of characters. Example Given s = "abcd", t = "dcab&q…
Description Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted list should be made by splicing together the nodes of the two lists and sorted in ascending order. Example Given 1->3->8->11->15->null,…
Description Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height. There may exist multiple valid solutions, return any of them. Example Given [1,2,3,4,5,6,7], return 4 / \ 2 6 / \ / \ 1 3 5 7 解题:题目要求根据一个有序的数…
Description Sort a linked list using insertion sort. Example Given 1->3->2->0->null, return 0->1->2->3->null. 解题:用插入法排序链表.很简单的一道题目,但还是出现了很多问题. 总结一下遇到的问题: (1)没有头结点的情况下,为了方便可以构造一个,返回头结点的next就行了. (2)没有必要一直在原来的链表上纠结,完全可以申请一个头结点,将原链表结点一…
Description Given 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 matter. Example Given an array [0,4,4,0,0,2,4,4], value…
Description Given a non-overlapping interval list which is sorted by start point. Insert a new interval into it, make sure the list is still in order and non-overlapping (merge intervals if necessary). Example Insert (2, 5) into [(1,2), (5,9)], we ge…
Description 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 nearest leaf node. Example Given a binary tree as follow: 1 / \ 2 3 / \ 4 5 The minimum depth is …