n-Queen
https://www.acmicpc.net/problem/9663
import sys
read=sys.stdin.readline
n=int(read().strip())
arr1=[0]*n # 같은 열
arr2=[0]*2*n # 같은 대각선(좌하단 -> 우상단)
arr3=[0]*2*n # 같은 대각선(좌상단 -> 우하단)
result=0
def func(row):
행이 n인
경우 : 전체 결과
result += 1
return
if row<n:
for col in range(n):
if arr1[col] or arr2[row+col] or arr3[row-col+n -1 ]:
continue
arr1[col]= 1
arr2[row+col]= 1
arr3[row-col+n -1 ]= 1
func(row+ 1 )
arr1[col]= 0
arr2[row+col]= 0
arr3[row-col+n -1 ]= 0
func( 0 )
print("결과 ",result)


하노이
실행 횟수 : (n-1) 개 원반의 이동 횟수를 A라고 할때 n 개 원반의 이동횟수는 2A+1이다
1 3 7 15 31 63 127
n : 1 2 3 4 5 6 7
실행 횟수의 일반항은 2^n-1 이다.
투포인터
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
# p1 : 고유값의 위치를 나타낸다
p1=0
# p2 : 다른 값의 위치를 가리킬려고 쓴다
for p2 in range(1,len(nums)):
if nums[p1]!=nums[p2]:
p1+=1
nums[p1]=nums[p2]
return p1+1