본문 바로가기

알고리즘 문제풀이/leetcode142

[leetcode 122] Best Time to Buy and Sell Stock II Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times). Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again). Example 1: Input: [7.. 2020. 11. 20.
[leetcode 125] Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: "A man, a plan, a canal: Panama" Output: true Example 2: Input: "race a car" Output: false 문제 풀이: 난이도 쉬움 class Solution { public boolean isPalindrome(String s) { s = s.toLowerCase(); int .. 2020. 11. 20.
[leetcode 118] Pascal's Triangle Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it. Example: Input: 5 Output: [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 문제 풀이 난이도 easy dp로 구현하면 되는 문제이다. 자바로 구현방법 익히기!!! class Solution { public List generate(int numRows) { List tr = new ArrayList(); if(numRows == 0){ return .. 2020. 11. 19.
[leetcode 66] Plus One Given a non-empty array of decimal digits representing a non-negative integer, increment one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element in the array contains a single digit. You may assume the integer does not contain any leading zero, except the number 0 itself. Example 1: Input: digits = [1,2,3] Output: [1,2,4] Explan.. 2020. 11. 19.