본문 바로가기

반응형

hacking or software engineering skills

(64)
6. ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H N A P L S I I G Y I R And then read line by line: "PAHNAPLSIIGYIR" Write the code that will take a string and make this conversion given a number of rows: string convert(string s, int numRows); Example 1: Input: s = "PAY..
5. Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2: Input: "cbbd" Output: "bb" class Solution: def longestPalindrome(self, s: str) -> str: length = len(s) if length == 0: return '' if length == 1: return s if length == 2: if s[0] == s[-1]: return ..
4. Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). You may assume nums1 and nums2 cannot be both empty. Example 1: nums1 = [1, 3] nums2 = [2] The median is 2.0 Example 2: nums1 = [1, 2] nums2 = [3, 4] The median is (2 + 3)/2 = 2.5 class Solution(object): def findMedianSortedAr..
3. Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Note that the answer must be a su..
2. Add Two Numbers You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example: Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 Explanation: 342 + 4..
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 input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. class Solution: def twoSum(self, nums, target): """ :type nums: List[int] :type ..
c++ OpenSource 이용하기 openCV와 MFC를 이용하는 과정에서openCV를 라이브러리로 설치하는 것이 너무나 오래걸렸다. 코드 작성하는 시간보다 openCV라이브러리 설치하고 그 문제를 파악하기 위해 수많은 주석을 지웠다 반복하며openCV함수들을 뜯어보는 미친 노가다를 하는 시간이 더 길었다. 10배차이 나는 visual studio 2010을 쓰므로 vs10 이 떠야하는데 처음 vs14가 떠서여러 오류들이 많았고 이에 해당하는 dll들을 다 추가하여도 잘 되지 않았다. 그래서 수많은 뻘짓 끝에... source파일을 받고 cmake를 썻다.이후 cmake를 통해 생성된 솔루션을 빌드(이때 릴리즈모드를 쓸경우 릴리즈모드에 관련된 lib,dll이 형성)를 했는데내가 원하는 건 디버그 모드 였는데 처음 릴리즈모드로 해서 또 여..
c++ polymorphism c++ 다형성 개념이 잘 이해가 안 가서 정리 c++은 상속성(inheritance)을 갖고 있기에, 기본클래스와 파생클래스가 있다. 이때 기본클래스 타입의 포인터를 이용하면 파생클래스또한 같이 다룰 수 있다. 단, 기본클래스 내에서 virtual function으로 정의 된 함수를 파생클래스에서 따로 정의하였을 때만 결과가 달라진다. ex) Shape 이란 기본 클래스와 Rectangle이란 파생클래스에서 Shape shape; Rectangle rectangle; Shape** pointers = new Shape*[2]; pointers[0] = &shape; pointers[1] = &rectangle; -> 이렇게 기본클래스 타입의 포인터는 파생클래스 포인터를 저장할 수 있고. pointers[..

728x90
반응형